Closed 4951fabd-1bd2-4941-b979-084cf05fde06 closed 5 years ago
OS: Debian testing
python3 -VV: Python 3.7.2+ (default, Feb 2 2019, 14:31:48) [gcc 8.2.0]
The following:
class Meta(type): pass
class X(metaclass=Meta):
def __class_getitem__(cls, key):
return key
X[10]
Results in
TypeError: 'Meta' object does not support indexing
However, PEP-560 specifically states that __class_getitem should be used as fall back for when a metaclass does not implement __getitem.
Yes, I think this is a bug. Created a PR with a possible simple fix.
New changeset ac28147e78c45a6217d348ce90ca5281d91f676f by Ivan Levkivskyi in branch 'master': bpo-35992: Use PySequence_GetItem only if sq_item is not NULL (GH-11857) https://github.com/python/cpython/commit/ac28147e78c45a6217d348ce90ca5281d91f676f
New changeset a7f929db605326da452fbdeebfe341afa9316d25 by Miss Islington (bot) in branch '3.7': bpo-35992: Use PySequence_GetItem only if sq_item is not NULL (GH-11857) https://github.com/python/cpython/commit/a7f929db605326da452fbdeebfe341afa9316d25
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields: ```python assignee = None closed_at =
created_at =
labels = ['interpreter-core', 'type-bug', '3.7', 'docs']
title = 'Metaclasses interfere with __class_getitem__'
updated_at =
user = 'https://github.com/cdonovick'
```
bugs.python.org fields:
```python
activity =
actor = 'levkivskyi'
assignee = 'docs@python'
closed = True
closed_date =
closer = 'levkivskyi'
components = ['Documentation', 'Interpreter Core']
creation =
creator = 'donovick'
dependencies = []
files = []
hgrepos = []
issue_num = 35992
keywords = ['patch']
message_count = 4.0
messages = ['335497', '335521', '335790', '335791']
nosy_count = 5.0
nosy_names = ['gvanrossum', 'docs@python', 'levkivskyi', 'miss-islington', 'donovick']
pr_nums = ['11857', '11910']
priority = 'normal'
resolution = 'fixed'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue35992'
versions = ['Python 3.7']
```