Currently __prepare__ only requires that the returned item implements __setitem__ and __getitem__. It appears that co_annotations require that the object actually must be a subclass of dict. Minimum code to reproduce.
class TestDict:
def __init__(self):
self.data = {}
def __setitem__(self, key, value):
self.data[key] = value
def __getitem__(self, item):
return self.data[item]
class CustomType(type):
@classmethod
def __prepare__(metacls, name, bases):
return TestDict()
def __new__(metacls, name, bases, namespace, /, **kwargs):
namespace = namespace.data
cls = super().__new__(metacls, name, bases, namespace, **kwargs)
return cls
class A(metaclass=CustomType):
val:str
A.__annotations__
#errors here
__new__ does require that the input to its third argument be a subclass of dictionary but any metaclass that handles it like above would be avoiding that issue.
Not sure if this is just a bad assertion and its not actually an issue for the code or if it is an issue with the code.
Currently __prepare__ only requires that the returned item implements __setitem__ and __getitem__. It appears that co_annotations require that the object actually must be a subclass of dict. Minimum code to reproduce.
__new__ does require that the input to its third argument be a subclass of dictionary but any metaclass that handles it like above would be avoiding that issue.
Not sure if this is just a bad assertion and its not actually an issue for the code or if it is an issue with the code.