STINNER Victor added the comment:

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__)
---

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue31336>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to