[docs] Superfluous dict() call in metaclass example?

Matthias Geier matthias.geier at gmail.com
Fri Aug 12 13:51:37 EDT 2016


Dear list.

Regarding this metaclass example:
https://docs.python.org/3.6/reference/datamodel.html#metaclass-example

It contains this line:

    result = type.__new__(cls, name, bases, dict(namespace))

I think the invocation of dict() here is superfluous and misleading.

It's explained in the paragraph directly above this section:

"""
When a new class is created by type.__new__, the object provided as
the namespace parameter is copied to a standard Python dictionary and
the original object is discarded. The new copy becomes the __dict__
attribute of the class object.
"""

Since a copy is made anyway, what's the use of calling dict() on the
OrderedDict instance?

I tried running the code without dict() and it still seems to work fine.

But maybe I'm wrong?

cheers,
Matthias


More information about the docs mailing list