bpo-46162: make property generic#30238
bpo-46162: make property generic#30238sobolevn wants to merge 6 commits intopython:mainpython/cpython:mainfrom
property generic#30238Conversation
kumaraditya303
left a comment
There was a problem hiding this comment.
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). |
| 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.
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.
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_propertyis already generic: https://github.com/python/cpython/blob/main/Lib/functools.py#L1002