| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM but the PEP should be changed first to account for this change.
Sorry, something went wrong.
|
@kumaraditya303 this was my exact question. Because, current version of PEP states:
I have several issues with that:
CC @ambv as PEP's author 🙂 |
Sorry, something went wrong.
@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 graphlib.TopologicalSorter). @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). |
Sorry, something went wrong.
| 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.
Sorry, something went wrong.
This changes property which is in the builtins which is very widely used and it not in other module so it should be mentioned in the PEP under 3.11 changes for maximum visibility about this change. |
Sorry, something went wrong.
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). |
Sorry, something went wrong.
| @@ -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?
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
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