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
Make builtins.property
generic
#90320
Comments
Original discussion in Short description:
Open questions:
|
One more question about PEP-585: it does not specify |
Yes, it is too late for 3.10 (but you can add it to typing_extensions). Also, PEP-585 is done, we don't update PEPs. Please do test with When this was first proposed (python/typing#985) there were worries about backwards compatibility. Given how common property is, we need to make sure there are no problems with that. Can you address that? I don't see it in the original thread. Also, since this requires type checkers to change, do we need a PEP? Finally. Please keep discussion in this bpo issue, don't have long discussions on the PR. (Honestly I think it's too soon for a PR given that we don't seem to have agreement in the typing tracker discussion.) |
Thanks, Guido!
Got it!
Done, PR is updated. Now we test that
I guess you were thinking about this one: python/typing#594 Here's a list of problem from the original thread: ## the returned value of property has no typing equivalent Now there is: ## There is no consistency in how properties in classes work in comparison to normal variables or functions Author points out that all python versions right now ignore Here's how it works before my patch: Python 3.10.0 (default, Nov 1 2021, 10:24:06) [Clang 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import get_type_hints
>>> class Some:
... @property
... def a(self) -> int:
... return 1
...
>>> get_type_hints(Some)
{}
>>> get_type_hints(Some.a)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/typing.py", line 1827, in get_type_hints
raise TypeError('{!r} is not a module, class, method, '
TypeError: <property object at 0x102b7a7f0> is not a module, class, method, or function. I've added a test case for my patch to make sure this behavior is not changed. And indeed, it works exactly the same as before. I've also covered a part from python/typing#594 (comment) Runtime introspection of ## Forward compat Users of python<3.11 will have
I cannot speak for all type-checkers, but I know how it works in mypy. Mypy already supports descriptors. So, this example works: class Desc:
def __get__(self, obj, typ) -> int: pass
class Some:
a = Desc()
s = Some()
reveal_type(s.a) # N: Revealed type is "builtins.int"
reveal_type(Some.a) # N: Revealed type is "builtins.int" The same just works for my All in all, I don't think that we need a PEP for three reasons:
Feedback on this is welcome! Maybe I am missing something.
This PR is really small. It took me like 30 mins, but we have a reference now. |
Does it mean that property[GetType, SetType] will be required and MyPy will complain if the raw property decorator be used? |
Serhiy, no, we can infer that. There are two general cases:
|
Since the conclusion is that we can't do this without breaking backwards compatibility, should we just close this? Or is there still a compromise possible? |
Looks like no one showed much interest in it :( Thanks everyone! |
property
generic #30238Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: