-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-122634: Deprecate __class_getitem__
on metaclasses
#122743
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Using :meth:`~object.__class_getitem__` on a metaclass is deprecated since | ||
3.14 and will be removed in 3.16, instead, use | ||
:meth:`~object.__class_getitem__` on regular classes or use | ||
:meth:`~object.__getitem__` on metaclasses. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5616,6 +5616,16 @@ _Py_type_getattro_impl(PyTypeObject *type, PyObject *name, int * suppress_missin | |
res = meta_get(meta_attribute, (PyObject *)type, | ||
(PyObject *)metatype); | ||
Py_DECREF(meta_attribute); | ||
if (res && PyUnicode_EqualToUTF8(name, "__class_getitem__")) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes it so the deprecation gets triggered if you use regular attribute access to access the attribute, but I don't think that's right:
Instead, the deprecation should trigger only if the lookup is triggered by the subscript operator, like in this example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that there's any clean way to do that. We don't have any info about that in Passing this info would require either a global state or a new parameter in several functions (some of which are public). Maybe I am missing something? I don't think that
|
||
if (PyErr_WarnEx(PyExc_DeprecationWarning, | ||
"Accessing __class_getitem__ on a metaclass is deprecated " | ||
"since 3.14 and will be removed in 3.16. " | ||
"Instead, define a regular __getitem__ method on a metaclass, " | ||
"if you need this behavior.", | ||
1) < 0) { | ||
return NULL; | ||
} | ||
} | ||
return res; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.