[New-bugs-announce] [issue43162] Enum regression: AttributeError when accessing class variables on instances

Miro Hrončok report at bugs.python.org
Mon Feb 8 07:22:59 EST 2021


New submission from Miro Hrončok <miro at hroncok.cz>:

I believe I found a regression in Enum in Python 3.10.0a5.

This is Python 3.9:

>>> import enum
>>> class C(enum.Enum):
...     A = 0
...     B = 1
... 
>>> C.A
<C.A: 0>
>>> C.B
<C.B: 1>
>>> C(0).A
<C.A: 0>
>>> C(0).B
<C.B: 1>
>>> 


The Enum instances can access class-attributes via dot, like normal instances do.


While in Python 3.10.0a5:

>>> import enum
>>> class C(enum.Enum):
...     A = 0
...     B = 1
... 
>>> C.A
<C.A: 0>
>>> C.B
<C.B: 1>
>>> C(0).A
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.10/enum.py", line 146, in __get__
    raise AttributeError(
AttributeError: C: no attribute 'A'
>>> C(0).B
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.10/enum.py", line 146, in __get__
    raise AttributeError(
AttributeError: C: no attribute 'B'





In real word situations, it breaks meson:

https://github.com/mesonbuild/meson/blob/398df5629863e913fa603cbf02c525a9f501f8a8/mesonbuild/backend/backends.py#L52-L78

The __str__ method does:

    if self is self.EXITCODE: ...

And it fails with:

    AttributeError: TestProtocol: no attribute 'EXITCODE'

This worked with 3.10.0a4.


If this is a deliberate backwards incompatible change of behavior, I don't think it is documented in the changelog or what's new in Python 3.10, nor that it was deprecated in Python 3.9 and 3.8.

----------
components: Library (Lib)
messages: 386626
nosy: hroncok
priority: normal
severity: normal
status: open
title: Enum regression: AttributeError when accessing class variables on instances
type: behavior
versions: Python 3.10

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


More information about the New-bugs-announce mailing list