| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
Sorry, something went wrong.
|
@rhettinger next, when we call get_type_hints we rely on an undocumented behavior of order of __annotations__/get_type_hints. Is this correct or am I missing anything? Should I open a bug? |
Sorry, something went wrong.
|
Friendly ping, it has been 5 months. |
Sorry, something went wrong.
|
@FFY00, have you considered using the inspect module to find the name of the first argument, and then checking for that in __annotations__? |
Sorry, something went wrong.
|
@taleinat thanks for the attention! I have, as pointed out in bpo. The issue is getting the correct first argument. This decorator operates before the method is registered in the class, so we don't know if we should skip the first argument (self) or not. This PR only fixes the issue of return annotation being used in the dispatch signature, it only mitigates the main problem. I am not sure how to properly address the root issue here. |
Sorry, something went wrong.
To my understanding, we have separate singledispatch and singledispatchmethod decorators, and singledispatchmethod "magically" takes care of the "self" arg. I haven't dug too deep into the intricacies of that code, though. Have you tried this with singledispatchmethod and seen a problem with the above mentioned approach? If so, please provide some details.
We really should solve the root issue. I don't think avoiding only using the return annotation, while still possibly using the annotation for another argument, is a reasonable fix, unless we've made a significant attempt at a thorough fix and have come to the conclusion that it would be unreasonably hard to do, or that it would break backwards-compatibility too harshly. |
Sorry, something went wrong.
Thank you for working on this, and sorry for the great delay in giving this any attention! |
Sorry, something went wrong.
Ah, sorry. I forgot about this 🙃 |
Sorry, something went wrong.
…singledispatch Signed-off-by: Filipe Laíns <lains@archlinux.org>
Signed-off-by: Filipe Laíns <lains@archlinux.org>
|
To solve this issue I added a _arg_index argument to register, which defaults to 0 and we set it to 1 when called via singledispatchmethod. I am not too happy about this, as it exposes a new argument. Let me know if you can think of a better way 😊 |
Sorry, something went wrong.
|
Friendly ping. |
Sorry, something went wrong.
|
just an extra comment: Unfortunately, we can't rely on isinstance(method, types.MethodType), which would have more cleanly solved the issue. |
Sorry, something went wrong.
| import inspect | ||
| try: | ||
| args = list(inspect.signature(cls).parameters.keys()) | ||
| except TypeError: |
There was a problem hiding this comment.
signature() can also raise a ValueError if no signature can be provided.
Sorry, something went wrong.
|
I synchronized the branch with main, but it seems that this solution is not compatible with other features added in recent years, so some existing tests now fail. |
Sorry, something went wrong.
|
Closing in face of that. I'll leave it for someone else to take up. |
Sorry, something went wrong.
It doesn't: #130827 |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
https://bugs.python.org/issue40464