-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
bpo-46162: make property
generic
#30238
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but the PEP should be changed first to account for this change.
@kumaraditya303 this was my exact question. Because, current version of PEP states:
I have several issues with that:
CC @ambv as PEP's author 🙂 |
@kumaraditya303 I am not sure how did you end up with this idea. PEP's are historical documents, and they don't get updated as the language grows. There were multiple occurrences of generic support for classes that the PEP initially did not target (the most recent one I recall is @sobolevn You can simply wait for a few core developers to respond, or just post this on the python-dev (since this is more of a change in the builtins). |
Lib/test/test_property.py
Outdated
def test_property___class_getitem__(self): | ||
from types import GenericAlias | ||
p = property[int, str] | ||
self.assertIsInstance(p, GenericAlias) | ||
self.assertIs(p.__origin__, property) | ||
self.assertEqual(p.__args__, (int, str)) | ||
self.assertEqual(p.__parameters__, ()) | ||
|
||
from typing import TypeVar | ||
G = TypeVar('G') | ||
S = TypeVar('S') | ||
p1 = property[G, S] | ||
self.assertEqual(p1.__args__, (G, S)) | ||
self.assertEqual(p1.__parameters__, (G, S)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see Lib/test_genericalias.py
as well for the tests.
This changes |
We generally do not change old PEPs, especially when they are in the Final state. A new discussion can (or should [depending on the complexity of this feature]) be brought up on python-dev, though for a case like this I'd personally suggest just waiting the final resolution in python/typing#985 and also the responses of other developers interested in typing before making an action towards python-dev since it might evolve a bit (which I personally do not expect). |
@@ -0,0 +1 @@ | |||
Make :class:`property` generic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
generic can be a bit vague (or generic 😉), could you rephrase this news snippet and the PR title to clarify this is about typing generic alias?
Original discussion: python/typing#985
https://bugs.python.org/issue46162
Related,
cached_property
is already generic: https://github.com/python/cpython/blob/main/Lib/functools.py#L1002