Message301887
Serhiy on the PR: "This is overgeneralization. Can tp_dict be not exact dict at all? I don't think this is possible. In many places concrete dict API is used with tp_dict. If you want to allow tp_dict be not exact dict, please open a separate issue for this." Using the following code, A.__dict__ type is dict even if the metaclass creates a different type, probably because type_new() calls PyDict_Copy(orig_dict): --- class mydict(dict): def __setitem__(self, name, value): if name == "__module__": value = "<mock module>" super().__setitem__(name, value) class MetaClass(type): @classmethod def __prepare__(mcl, name, bases): return mydict() class A(metaclass=MetaClass): pass print(A.__module__) --- | |
| Date | User | Action | Args | | 2017-09-11 16:53:22 | vstinner | set | recipients: + vstinner, rhettinger, pitrou, scoder, christian.heimes, methane, serhiy.storchaka | | 2017-09-11 16:53:21 | vstinner | set | messageid: <1505148801.98.0.858951465781.issue31336@psf.upfronthosting.co.za> | | 2017-09-11 16:53:21 | vstinner | link | issue31336 messages | | 2017-09-11 16:53:21 | vstinner | create | | |