Repository navigation
typing.Annotated fails for functions returning UUIDs #115165
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Feb 8, 2024 Thanks for the report!
Arguably there are two bugs here:
- Why is the
uuidmodule raisingTypeErrorfrom a__setattr__method? That seems like an antipattern; it should probably be raisingAttributeError. We probably can't change that now, though, for backwards-compatibility reasons - Yes, the
typingmodule should indeed be more careful here. Feel free to send a PR — I thinkexcept Exceptionmight actually be better here than just addingTypeErrorto theexceptclause. Otherwise we'll just get this bug reported again when somebody tries to useAnnotatedwith a class that raises e.g.RuntimeError(or whatever) from its__setattr__method
- Why is the
- addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Feb 8, 2024 - added 4 commits that reference this issue
on Feb 9, 2024 Thanks for the report, and the fix!
- added a commit that references this issue
on Feb 22, 2024
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Bug report
Bug description:
typing.Annotatedtries to set an attribute on the return value of calling an annotated callable. This fails when the returned object is immutable. I believe that addingTypeErrorto theexceptclause intyping. _BaseGenericAlias.__call__will fix the problem. I'm not sure if there are more cases of the same pattern or not.cpython/Lib/typing.py
Lines 1128 to 1131 in 17689e3
Example
Result
CPython versions tested on:
3.9, 3.10, 3.11, 3.12
Operating systems tested on:
macOS
Linked PRs
typing.Annotatedfor immutable types (GH-115213) #115227typing.Annotatedfor immutable types (GH-115213) #115228