Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Should typing be calling getattr on arbitrary classes? #113320

Closed
Assignees
AlexWaygood
Labels
3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
@Gobot1234

Description

@Gobot1234

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 buildshttps://github.com/Gobot1234/steam.py/actions/runs/7276342755/job/19825996032

MRE:

fromenumimportIntEnumfromtypingimportProtocolclassclassproperty:def__init__(self,func):self.__func__=funcdef__get__(self,instance,type):returnself.__func__(type)class_CommentThreadType(IntEnum):WorkshopAccountDeveloper=2classCommentable(Protocol):@classpropertydef_COMMENTABLE_TYPE(cls):return_CommentThreadType[cls.__name__]

Traceback onmain:

Running Debug|x64 interpreter...Traceback (most recent call last):  File"C:\Users\alexw\coding\test_protocol.py", line14, in<module>classCommentable(Protocol):...<2 lines>...return _CommentThreadType[cls.__name__]  File"C:\Users\alexw\coding\cpython\Lib\typing.py", line1838, in__init__cls.__callable_proto_members_only__=all(~~~^callable(getattr(cls, attr,None))for attrincls.__protocol_attrs__^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^    )^  File"C:\Users\alexw\coding\cpython\Lib\typing.py", line1839, in<genexpr>callable(getattr(cls, attr,None))for attrincls.__protocol_attrs__~~~~~~~^^^^^^^^^^^^^^^^^  File"C:\Users\alexw\coding\test_protocol.py", line9, in__get__returnself.__func__(type)~~~~~~~~~~~~~^^^^^^  File"C:\Users\alexw\coding\test_protocol.py", line17, in_COMMENTABLE_TYPEreturn _CommentThreadType[cls.__name__]~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^  File"C:\Users\alexw\coding\cpython\Lib\enum.py", line763, in__getitem__returncls._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

Linked PRs

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp