Message357857
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. |
|
Date |
User |
Action |
Args |
2019-12-05 16:01:20 | asvetlov | set | recipients:
+ asvetlov, gvanrossum, yselivanov, levkivskyi |
2019-12-05 16:01:20 | asvetlov | set | messageid: <1575561680.53.0.527773228466.issue38978@roundup.psfhosted.org> |
2019-12-05 16:01:20 | asvetlov | link | issue38978 messages |
2019-12-05 16:01:20 | asvetlov | create | |
|