Nick Coghlan added the comment:

I hadn't noticed that type.__new__ copied the contents (it surprises me that it 
does both that *and* restricts the input type to a true dict instance).

The "Extending a class" example should still work as shown, since the magic of 
that happens while the body of ExtendedExample is running.

For the order preserving case, it turns out CPython already keeps a copy of the 
original namespace around as cls.__locals__, but this is currently undocumented 
(as far as I can tell anyway).

If we elevate that to documented behaviour, then __init_class__ implementations 
can reference both the original object, as well as the snapshot underlying the 
class object.

Given that, it is probably also better to revert the namespace keyword to 
accepting an instance rather than a factory function, since the copy operation 
after execution of the class body is automatic.

----------

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

Reply via email to