[issue38978] Implement __class_getitem__ for Future, Task, Queue
Andrew Svetlov
report at bugs.python.org
Thu Dec 5 11:01:20 EST 2019
Andrew Svetlov <andrew.svetlov at gmail.com> added the comment:
I thought __class_getitem__ was invented exactly to simplify generic types support.
The only thing that confuses me an example from PEP 560:
class MyList:
def __getitem__(self, index):
return index + 1
def __class_getitem__(cls, item):
return f"{cls.__name__}[{item.__name__}]"
It prevents from instantiating a generic on inheritance, e.g. the following code raises TypeError:
class MyOtherList(MyList[int]):
pass
It would be nice if Ivan clarifies what is the best practice in this case.
I think the method should return unmodified class, not a string.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38978>
_______________________________________
More information about the Python-bugs-list
mailing list