I have been spending my Google sprint time on writing and implementing PEP 362 (http://www.python.org/dev/peps/pep-0362/), which finally defines Signature objects for functions. With the implementation at a place I am happy with, I wanted to ask about the open issues with the PEP. The first question is whether to have Signature objects on all functions by default or to leave it in the 'inspect' module and have it be something totally optional. My vote is the latter for now and we can add them to all functions if they turn out to be useful and popular. The second open issue is how to handle binding arguments to tuple parameters for the Signature.bind() method. If you have the function ``def foo((a, b): pass``, how do you have the Signature.bind() method handle 'a', and 'b'? You can either take the proposed arguments and in the dict mapping arguments to parameters have an entry for 'a' and 'b' individually, or have an entry for '(a, (b,))'. My vote is the latter since you cannot address 'a' or 'b' individually as keyword arguments and this makes more sense with function annotations since they won't apply to 'a' and 'b' individually but instead to the entire tuple. Either way there is the issue of exhausting an iterator (like a generator) trying to find out if it is the proper length to unpack, for which I raise a TypeError instead of exhaust a possibly mutable iterator currently. -Brett
Brett Cannon wrote:
I have been spending my Google sprint time on writing and implementing PEP 362 (http://www.python.org/dev/peps/pep-0362/), which finally defines Signature objects for functions. With the implementation at a place I am happy with, I wanted to ask about the open issues with the PEP.
While reading the PEP, I stumbled over the description of the bind() method. As I understand the implementation patch, the parameter names will be keys and the arguments values in the resulting dictionary, but this sentence looks to me as if it describes it the opposite way (it also doesn't clarify that "parameter" means "parameter name"): * bind(*args, **kwargs) -> dict Create a mapping from argument to parameter for the signature (see `Open Issues`_ for question of how to handle tuples). Another question: could it be helpful to make Parameter.default_value a weak reference? Georg
On 8/23/06, Georg Brandl
Brett Cannon wrote:
I have been spending my Google sprint time on writing and implementing PEP 362 (http://www.python.org/dev/peps/pep-0362/), which finally defines Signature objects for functions. With the implementation at a place I am happy with, I wanted to ask about the open issues with the PEP.
While reading the PEP, I stumbled over the description of the bind() method.
As I understand the implementation patch, the parameter names will be keys and the arguments values in the resulting dictionary, but this sentence looks to me as if it describes it the opposite way (it also doesn't clarify that "parameter" means "parameter name"):
* bind(*args, **kwargs) -> dict Create a mapping from argument to parameter for the signature (see `Open Issues`_ for question of how to handle tuples).
You're right, it's a typo. Another question: could it be helpful to make Parameter.default_value a
weak reference?
Perhaps, but I don't think it is necessarily required. I can change it if others want to go that way, but for now I am happy with the way it is. -Brett
Brett Cannon wrote:
Another question: could it be helpful to make Parameter.default_value a weak reference?
Perhaps, but I don't think it is necessarily required. I can change it if others want to go that way, but for now I am happy with the way it is.
Leave it as a normal reference - if I have a reference to a Signature object, I'd like all it's attributes to stick around, thank you very much :) Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia --------------------------------------------------------------- http://www.boredomandlaziness.org
participants (3)
-
Brett Cannon
-
Georg Brandl
-
Nick Coghlan