Open
Description
Bug report
For example the following program fails with either assert WeirdClass.value == 2
or assert WeirdClass.value == 3
in recent Python versions:
import sys
class Base:
value = 1
class Meta(type):
def mro(cls):
return (cls, Base, object)
class WeirdClass(metaclass=Meta):
pass
assert Base.value == 1
assert WeirdClass.value == 1
Base.value = 2
assert Base.value == 2
assert WeirdClass.value == 2
Base.value = 3
assert Base.value == 3
assert WeirdClass.value == 3
Adding intervening calls to sys _clear_internal_caches()
makes the test pass.
Version | Result |
---|---|
3.7 | OK |
3.8 | OK |
3.9 | OK |
3.10 | AssertionError: assert WeirdClass.value == 2 |
3.11 | AssertionError: assert WeirdClass.value == 2 |
3.12 | AssertionError: assert WeirdClass.value == 2 |
3.13 | AssertionError: assert WeirdClass.value == 3 |
main | AssertionError: assert WeirdClass.value == 3 |
We have code that checks for this case, but it hasn't worked properly in Python 3.10+:
Lines 1107 to 1112 in 5c89adf
We also have a test that partly covers this case, but doesn't detect the bug:
cpython/Lib/test/test_capi/test_type.py
Lines 40 to 66 in 5c89adf
Linked PRs
Metadata
Metadata
Assignees
Labels
only security fixesonly security fixesbugs and security fixesbugs and security fixesbugs and security fixesbugs and security fixes(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)An unexpected behavior, bug, or errorAn unexpected behavior, bug, or error