Closed
Description
Bug report
Bug description:
I was updating my CI to support python3.12 and ran into the following error that isn't present in the 3.12 builds https://github.com/Gobot1234/steam.py/actions/runs/7276342755/job/19825996032
MRE:
from enum import IntEnum
from typing import Protocol
class classproperty:
def __init__(self, func):
self.__func__ = func
def __get__(self, instance, type):
return self.__func__(type)
class _CommentThreadType(IntEnum):
WorkshopAccountDeveloper = 2
class Commentable(Protocol):
@classproperty
def _COMMENTABLE_TYPE(cls):
return _CommentThreadType[cls.__name__]
Traceback on main
:
Running Debug|x64 interpreter...
Traceback (most recent call last):
File "C:\Users\alexw\coding\test_protocol.py", line 14, in <module>
class Commentable(Protocol):
...<2 lines>...
return _CommentThreadType[cls.__name__]
File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1838, in __init__
cls.__callable_proto_members_only__ = all(
~~~^
callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\alexw\coding\cpython\Lib\typing.py", line 1839, in <genexpr>
callable(getattr(cls, attr, None)) for attr in cls.__protocol_attrs__
~~~~~~~^^^^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\test_protocol.py", line 9, in __get__
return self.__func__(type)
~~~~~~~~~~~~~^^^^^^
File "C:\Users\alexw\coding\test_protocol.py", line 17, in _COMMENTABLE_TYPE
return _CommentThreadType[cls.__name__]
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^
File "C:\Users\alexw\coding\cpython\Lib\enum.py", line 763, in __getitem__
return cls._member_map_[name]
~~~~~~~~~~~~~~~~^^^^^^
KeyError: 'Commentable'
Should typing be more careful about accessing random attributes on classes to prevent these kinds of errors in the future?
CPython versions tested on:
3.12
Operating systems tested on:
macOS