From 6a0038bdb54f36616b0b578471ab31586e2af731 Mon Sep 17 00:00:00 2001 From: Radomir Stevanovic Date: Thu, 27 Jul 2023 13:31:16 -0700 Subject: [PATCH] Fix `ForwardRef` wrapper for py 3.10.0 (shim until bpo-45166) (#6919) --- pydantic/_internal/_typing_extra.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pydantic/_internal/_typing_extra.py b/pydantic/_internal/_typing_extra.py index b576577244..21524df6a6 100644 --- a/pydantic/_internal/_typing_extra.py +++ b/pydantic/_internal/_typing_extra.py @@ -253,7 +253,7 @@ def get_function_type_hints( return type_hints -if sys.version_info < (3, 9, 8): +if sys.version_info < (3, 9, 8) or (3, 10) <= sys.version_info < (3, 10, 1): def _make_forward_ref( arg: Any, @@ -262,11 +262,13 @@ def _make_forward_ref( is_class: bool = False, ) -> typing.ForwardRef: """Wrapper for ForwardRef that accounts for the `is_class` argument missing in older versions. - The `module` argument is omitted as it breaks <3.9.8 and isn't used in the calls below. + The `module` argument is omitted as it breaks <3.9.8, =3.10.0 and isn't used in the calls below. See https://github.com/python/cpython/pull/28560 for some background. The backport happened on 3.9.8, see: - https://github.com/pydantic/pydantic/discussions/6244#discussioncomment-6275458. + https://github.com/pydantic/pydantic/discussions/6244#discussioncomment-6275458, + and on 3.10.1 for the 3.10 branch, see: + https://github.com/pydantic/pydantic/issues/6912 Implemented as EAFP with memory. """