PEP 362 Second Revision
Hello, The new revision of PEP 362 has been posted: http://www.python.org/dev/peps/pep-0362/ Thanks to Brett, Larry, Nick, and everybody else on python-dev for your corrections/suggestions. Summary of changes: 1. We don't cache signatures in __signature__ attribute implicitly 2. signature() function is now more complex, but supports methods, partial objects, classes, callables, and decorated functions 3. Signatures are always constructed on demand 4. Dropped the deprecation section The implementation is not aligned with the latest PEP yet, I'll try to update it tonight. Thanks, - Yury
On 6/7/2012 10:41 AM, Yury Selivanov wrote:
Hello,
The new revision of PEP 362 has been posted: http://www.python.org/dev/peps/pep-0362/
Thanks to Brett, Larry, Nick, and everybody else on python-dev for your corrections/suggestions.
Summary of changes:
1. We don't cache signatures in __signature__ attribute implicitly
2. signature() function is now more complex, but supports methods, partial objects, classes, callables, and decorated functions
3. Signatures are always constructed on demand
4. Dropped the deprecation section
I like this now. Being more able to get the actual signature of partials and wraps will be a win. If the signature object has a decent __str__/__repr__ method, I would (try to remember) to revise idle tooltips (for whichever version) to check for .__signature__ before inspect'ing. -- Terry Jan Reedy
On 2012-06-07, at 3:54 PM, Terry Reedy wrote:
On 6/7/2012 10:41 AM, Yury Selivanov wrote:
Hello,
The new revision of PEP 362 has been posted: http://www.python.org/dev/peps/pep-0362/
Thanks to Brett, Larry, Nick, and everybody else on python-dev for your corrections/suggestions.
Summary of changes:
1. We don't cache signatures in __signature__ attribute implicitly
2. signature() function is now more complex, but supports methods, partial objects, classes, callables, and decorated functions
3. Signatures are always constructed on demand
4. Dropped the deprecation section
I like this now. Being more able to get the actual signature of partials and wraps will be a win. If the signature object has a decent __str__/__repr__ method, I would (try to remember) to revise idle tooltips (for whichever version) to check for .__signature__ before inspect'ing.
I think we'll add a 'format' method to the Signature, that will work like 'inspect.formatargspec'. 'Signature.__str__' will use it with default parameters/formatters. I'm not sure how __repr__ should look like. Maybe default repr (object.__repr__) is good enough. - Yury
On 6/7/2012 4:54 PM, Yury Selivanov wrote:
I think we'll add a 'format' method to the Signature, that will work like 'inspect.formatargspec'. 'Signature.__str__' will use it with default parameters/formatters.
Great. If I don't like the default, I could customize.
I'm not sure how __repr__ should look like. Maybe default repr (object.__repr__) is good enough.
__repr__ = __str__ is common. Idle tooltips use an re to strip 'self[, ]' from the inspect.formatargspec result*. I have revised the code to only do that when appropriate (for bound instance methods and callable instances), which is to say, when the user has already entered the object that will become the self parameter). If signature does the same, I might delete the code and use the signature object instead. *The same could be done for class methods, but I am not sure that 'cls' is standard enough to bother. Of course, any function using anything other than 'self' will also not see the deletion. Come to think of it, now that I am doing the search-and-replace conditionally rather than always, I can and should re-write the re to remove the first name rather than 'self' specifically. It will be good to have all such signature manipulations done correctly in one place. --- Terry Jan Reedy
On 2012-06-07, at 5:39 PM, Terry Reedy wrote:
On 6/7/2012 4:54 PM, Yury Selivanov wrote:
I think we'll add a 'format' method to the Signature, that will work like 'inspect.formatargspec'. 'Signature.__str__' will use it with default parameters/formatters.
Great. If I don't like the default, I could customize.
Can you tell me how do you use those customizations (i.e. formatvarargs, formatarg and other arguments of formatargspec)?
I'm not sure how __repr__ should look like. Maybe default repr (object.__repr__) is good enough.
__repr__ = __str__ is common.
Idle tooltips use an re to strip 'self[, ]' from the inspect.formatargspec result*. I have revised the code to only do that when appropriate (for bound instance methods and callable instances), which is to say, when the user has already entered the object that will become the self parameter). If signature does the same, I might delete the code and use the signature object instead.
*The same could be done for class methods, but I am not sure that 'cls' is standard enough to bother. Of course, any function using anything other than 'self' will also not see the deletion. Come to think of it, now that I am doing the search-and-replace conditionally rather than always, I can and should re-write the re to remove the first name rather than 'self' specifically. It will be good to have all such signature manipulations done correctly in one place.
Well, signature won't strip parameters based on their names, but rather based on the callable type. If it's a method, than no matter how its first parameter is named - it will be omitted. Same applies for classmethods. - Yury
On Thu, 07 Jun 2012 17:39:54 -0400, Terry Reedy <tjreedy@udel.edu> wrote:
On 6/7/2012 4:54 PM, Yury Selivanov wrote:
I think we'll add a 'format' method to the Signature, that will work like 'inspect.formatargspec'. 'Signature.__str__' will use it with default parameters/formatters.
Great. If I don't like the default, I could customize.
I'm not sure how __repr__ should look like. Maybe default repr (object.__repr__) is good enough.
__repr__ = __str__ is common.
I think you meant __str__ = __repr__. __repr__ is the more fundamental of the two, and if there is no __str__, it defaults to __repr__. IMO the __repr__ should make it clear that it is a signature object somehow. --David
On Thu, Jun 7, 2012 at 10:41 AM, Yury Selivanov <yselivanov.ml@gmail.com> wrote:
Hello,
The new revision of PEP 362 has been posted: http://www.python.org/dev/peps/pep-0362/
While the actual implementation is more complex, the PEP is a lot more clear and direct than it first was. Great job! I'm really looking forward to this, after working through essentially the same problems as part of tracerlib. So this has a huge thumbs up from me, fwiw.
Thanks to Brett, Larry, Nick, and everybody else on python-dev for your corrections/suggestions.
Summary of changes:
1. We don't cache signatures in __signature__ attribute implicitly
2. signature() function is now more complex, but supports methods, partial objects, classes, callables, and decorated functions
3. Signatures are always constructed on demand
4. Dropped the deprecation section
The implementation is not aligned with the latest PEP yet, I'll try to update it tonight.
Thanks, - Yury _______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/ironfroggy%40gmail.com
-- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://techblog.ironfroggy.com/ Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy
participants (4)
-
Calvin Spealman
-
R. David Murray
-
Terry Reedy
-
Yury Selivanov