[Python-Dev] PEP 362 Third Revision (original) (raw)
Yury Selivanov yselivanov.ml at gmail.com
Thu Jun 14 19:09:25 CEST 2012
- Previous message: [Python-Dev] PEP 362 Third Revision
- Next message: [Python-Dev] PEP 362 Third Revision
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 2012-06-14, at 12:03 PM, Ethan Furman wrote:
Yury Selivanov wrote:
Hello, The new revision of PEP 362 has been posted: http://www.python.org/dev/peps/pep-0362/ It's possible to test Signatures for equality. Two signatures are equal when they have equal parameters and return annotations. Possibly a dumb question, but do the parameter names have to be the same to compare equal? If yes, is there an easy way to compare two signatures by annotations alone?
Yes, parameter names have be the same.
You need to write a custom compare function for Parameters, that will check that two have (or both don't) equal annotations and kinds, and then write a compare function for Signatures, that will test return_annotations and 'parameters' collections.
All in all, shouldn't be longer than 10-15 lines of code.
Another "solution" to the problem could be adding a new 'annotations' read-only dynamic property to the Signature, that would iterate through parameters and produce a single dict. But this solution has a serious flaw, as signature of:
def foo(a:int, *, b:int) -> float
is not equal to the signature of:
def bar(a:int, b:int) -> float
and certainly not the signature of:
def spam(*args:int, **kwargs:int) -> float
So the most correct approach here is the one I described in the first place.
Thanks,
- Yury
- Previous message: [Python-Dev] PEP 362 Third Revision
- Next message: [Python-Dev] PEP 362 Third Revision
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]