GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — [doc] bpo-45680: Disambiguate ``__getitem__`` and ``__class_getitem__`` in the data model. by AlexWaygood · Pull Request #29389 · python/cpython Conversation
|
Thank you <3 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This is pretty cool, thanks for being so thorough.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Massive thanks for the detailed review! I've rewritten large chunks in response 😅 (Wow, writing documentation is hard!) |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| Usually, the :ref:`subscription<subscriptions>` of an object using square | ||
| brackets will call the :meth:`~object.__getitem__` instance method defined on | ||
| the object's class. However, if the object being subscribed is itself a class, |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should it be "object being subscribed", or "object being subscripted"?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def subscribe(obj, x): | ||
| class_of_obj = type(obj) | ||
|
|
||
| # If the class of `obj` defines `__getitem__()`, | ||
| # call `type(obj).__getitem__()` | ||
| if hasattr(class_of_obj, '__getitem__'): | ||
| return class_of_obj.__getitem__(obj, x) | ||
|
|
||
| # Else, if `obj` defines `__class_getitem__()`, | ||
| # call `obj.__class_getitem__()` | ||
| elif hasattr(obj, '__class_getitem__'): | ||
| return obj.__class_getitem__(x) | ||
|
|
||
| # Else, raise an exception | ||
| else: | ||
| raise TypeError( | ||
| f"'{class_of_obj.__name__}' object is not subscriptable" | ||
| ) |
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Please correct me if this isn't quite right -- I'm in a little over my head here!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Okay, the CI failures are because |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AlexWaygood for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks @AlexWaygood for the PR, and @ambv for merging it 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-29619 is a backport of this pull request to the 3.9 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…`` in the data model (pythonGH-29389) The documentation explaining Python's data model does not adequately explain the differences between ``__getitem__`` and ``__class_getitem__``, nor does it explain when each is called. There is an attempt at explaining ``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but this does not give sufficient clarity into how the method works. Moreover, it is the wrong place for that information to be found; the explanation of ``__class_getitem__`` should be in the documentation explaining the data model. This PR has been split off from pythonGH-29335. (cherry picked from commit 31b3a70) Co-authored-by: Alex Waygood <[email protected]>
|
GH-29620 is a backport of this pull request to the 3.10 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…`` in the data model (pythonGH-29389) The documentation explaining Python's data model does not adequately explain the differences between ``__getitem__`` and ``__class_getitem__``, nor does it explain when each is called. There is an attempt at explaining ``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but this does not give sufficient clarity into how the method works. Moreover, it is the wrong place for that information to be found; the explanation of ``__class_getitem__`` should be in the documentation explaining the data model. This PR has been split off from pythonGH-29335. (cherry picked from commit 31b3a70) Co-authored-by: Alex Waygood <[email protected]>
…titem__`` in the data model (GH-29389) (GH-29620) The documentation explaining Python's data model does not adequately explain the differences between ``__getitem__`` and ``__class_getitem__``, nor does it explain when each is called. There is an attempt at explaining ``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but this does not give sufficient clarity into how the method works. Moreover, it is the wrong place for that information to be found; the explanation of ``__class_getitem__`` should be in the documentation explaining the data model. This PR has been split off from GH-29335. (cherry picked from commit 31b3a70) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
…item__`` in the data model (GH-29389) (GH-29619) The documentation explaining Python's data model does not adequately explain the differences between ``__getitem__`` and ``__class_getitem__``, nor does it explain when each is called. There is an attempt at explaining ``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but this does not give sufficient clarity into how the method works. Moreover, it is the wrong place for that information to be found; the explanation of ``__class_getitem__`` should be in the documentation explaining the data model. This PR has been split off from GH-29335. (cherry picked from commit 31b3a70) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
…`` in the data model (pythonGH-29389) The documentation explaining Python's data model does not adequately explain the differences between ``__getitem__`` and ``__class_getitem__``, nor does it explain when each is called. There is an attempt at explaining ``__class_getitem__`` in the documentation for ``GenericAlias`` objects, but this does not give sufficient clarity into how the method works. Moreover, it is the wrong place for that information to be found; the explanation of ``__class_getitem__`` should be in the documentation explaining the data model. This PR has been split off from pythonGH-29335.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.