[3.12] gh-115165: Fix typing.Annotated for immutable types (GH-115213) (#115227)

gh-115165: Fix `typing.Annotated` for immutable types (GH-115213)

The return value from an annotated callable can raise any exception from
__setattr__ for the `__orig_class__` property.
(cherry picked from commit 564385612c)

Co-authored-by: dave-shawley <daveshawley@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-02-09 23:31:57 +01:00 committed by GitHub
parent 3539b02873
commit 321ec5e0fe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 1 deletions

View file

@ -1140,7 +1140,9 @@ class _BaseGenericAlias(_Final, _root=True):
result = self.__origin__(*args, **kwargs)
try:
result.__orig_class__ = self
except AttributeError:
# Some objects raise TypeError (or something even more exotic)
# if you try to set attributes on them; we guard against that here
except Exception:
pass
return result