This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author yselivanov
Recipients brett.cannon, larry, ncoghlan, yselivanov
Date 2014-03-31.20:30:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1396297836.4.0.601810070188.issue21117@psf.upfronthosting.co.za>
In-reply-to
Content
There is a small detail in the current Signature class implementation, in regards to how partial signatures are treated. Consider the following example:

   def foo(a, b): pass
   foo_partial = functools.partial(foo, 'spam')

Now, the signature of 'foo_partial' is '(a="spam", b)', which (strictly speaking) is not a valid python function signature. For cases like that, we have a private "Parameter._partial_kwarg" attribute. When this attribute is set to True, it means, that this parameter's default came from partial (or alike) function. Parameter instances with '_partial_kwarg=True' are treated a bit differently during signature validation and binding.

A small and nasty detail: Parameter.__eq__ ignores value of '_partial_kwarg'. Because, for the following code:

   def bar(a, b=10): pass
   def baz(a, b): pass
   baz2 = functools.partial(baz, b=10)

signature of 'bar' is equal to 'baz2'.

In light of making signatures hashable, the obvious question was raised: should __hash__ account for '_partial_kwarg' value or not.  I think it should.  But in this case, it should be really obvious, if parameter was modified by partial or not.

Hence, I propose to add two more classes:

- PartialSignature(Signature)
- PartialParameter(Parameter)

Results of signature(functools.partial(..)) and Signature.bind_partial(..) will be instances of PartialSignature. It will be OK if some PartialSignature is equal to Signature, but they will have different __hash__es.

What do you think?
History
Date User Action Args
2014-03-31 20:30:36yselivanovsetrecipients: + yselivanov, brett.cannon, ncoghlan, larry
2014-03-31 20:30:36yselivanovsetmessageid: <1396297836.4.0.601810070188.issue21117@psf.upfronthosting.co.za>
2014-03-31 20:30:36yselivanovlinkissue21117 messages
2014-03-31 20:30:35yselivanovcreate