[New-bugs-announce] [issue29794] Incorrect error message on invalid __class__ assignments

ppperry report at bugs.python.org
Sat Mar 11 11:00:21 EST 2017


New submission from ppperry:

If you try to set the __class__ of a type which doesn't support "__class__" assignments, you get the error message:

    TypeError: __class__ assignment only supported for heap types or ModuleType subclasses

However, the actual restriction doesn't require a subclass of "ModuleType"; the below code works:

    import random
    class M(type(random)):pass
    random.__class__ = M

Thus the error message is incorrect.

----------
components: Interpreter Core
messages: 289448
nosy: ppperry
priority: normal
severity: normal
status: open
title: Incorrect error message on invalid __class__ assignments
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29794>
_______________________________________


More information about the New-bugs-announce mailing list