[New-bugs-announce] [issue28866] Unexpected behavior resulting from mro() and __setattr__ in interactive mode

sjpalt report at bugs.python.org
Sun Dec 4 09:35:45 EST 2016


New submission from sjpalt:

I ran into a strange bug while experimenting with metaclasses that implement a custom mro() method. It only seems to occur in interactive mode, either returning completely unrelated values or causing a segfault. Python 2 appears unaffected. I have been able to reproduce this with the following code:

# $ python -i weird.py
# >>> proxy.x
# 52011448
# >>> proxy.x
# 6160
# ...

class Foo:
    pass

class Meta(type):
    def mro(cls):
        return (cls, Foo, object)

    def __setattr__(cls, name, value):
        setattr(Foo, name, value)

proxy = Meta('FooProxy', (), {})

proxy.x = 300
proxy.x  # don't omit
proxy.x = 0

----------
components: Interpreter Core
files: weird.py
messages: 282344
nosy: sjpalt
priority: normal
severity: normal
status: open
title: Unexpected behavior resulting from mro() and __setattr__ in interactive mode
type: crash
versions: Python 3.4, Python 3.5
Added file: http://bugs.python.org/file45752/weird.py

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


More information about the New-bugs-announce mailing list