[issue47136] Wrong value assigned automatically to the variable __module__ in the class body.

Steven D'Aprano report at bugs.python.org
Sun Mar 27 17:35:28 EDT 2022


Steven D'Aprano <steve at pearwood.info> added the comment:

> the programmer may use the variable __name__ for some other purposes

Dunder names like `__name__` are reserved for the use of the interpreter. If the programmer uses them for "other purposes", the programmer is responsible for any failures.

You wouldn't write:

    class MyList(list):
        __len__ = "Hello world!"

and then be surprised that MyList is broken. You shouldn't be surprised if setting `__name__` to an invalid value breaks things either.

----------
nosy: +steven.daprano

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue47136>
_______________________________________


More information about the Python-bugs-list mailing list