-
-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Self being a typing._SpecialForm prevents a case from PEP 673 #26
Comments
Hi, I'm not entirely sure what can be done here until the PEP is accepted and I can change https://github.com/python/cpython/blob/e0f8a3e9b96bbc2597f61be96993ef0c768a19fe/Lib/typing.py#L176 to if arg in (Any, NoReturn, Final, Self): If you have any suggestions for how to fix this now, I'd be more than happy to implement them. However, if you need this to work right now you you have a few options:
|
We can probably fudge things in typing-extensions so that it's not an instance of |
@Gobot1234 Yes, for my use case I'm using a string as ForwardRef now. I just wondered if I were doing something wrong. @JelleZijlstra Like vendoring the _SpecialForm from the cpython 3.11 codebase? Or a more elegant fudge? Namespaces are one honking great idea :-) |
Yes, vendoring would be the way to go. The place where this throws lets things it doesn't recognize through, so if we just make Self look like an unrelated object, it should pass. |
Adds a local copy of _SpecialForm in our namespace, so typing._type_check won't raise TypeError. (#964)
Something like this? |
Adds a local copy of _SpecialForm in our namespace, so typing._type_check won't raise TypeError. (#964)
Adds a local copy of _SpecialForm in our namespace, so typing._type_check won't raise TypeError. (#964) Co-authored-by: James Hilton-Balfe <[email protected]>
Adds a local copy of _SpecialForm in our namespace, so typing._type_check won't raise TypeError. (#964) Co-authored-by: James Hilton-Balfe <[email protected]>
This still happens with
|
This is an issue with mypy not yet fully supporting typing_extensions.Self, you might be interested in python/mypy#13133, the runtime works as expected |
Among the valid locations for Self in PEP 673 we find:
But
typing._type_check
regardstyping._SpecialForm
instances invalid type argumentshttps://github.com/python/cpython/blob/e0f8a3e9b96bbc2597f61be96993ef0c768a19fe/Lib/typing.py#L179
So this use will result in a
This also affects uses in linked lists and recursive dataclasses lke
The text was updated successfully, but these errors were encountered: