Override Python metaclass __getitem__
问题 Given the following code, I expect a return value of 'overridden' not 'value1' : class MyMetaclass(type): def __new__(cls, name, bases, attrs): attrs.update({'_my_dict': {'key1': 'value1', 'key2': 'value2'}}) return super().__new__(cls, name, bases, attrs) def __getitem__(cls, value): return cls._my_dict[str(value)] class MyBaseClass(metaclass=MyMetaclass): pass class MyClass(MyBaseClass): @classmethod def __getitem__(cls, value): return 'overridden' >>> MyClass['key1'] 'value1' # I expect: