From 4964bcd174c280524cf9315f63f4de69a84dae97 Mon Sep 17 00:00:00 2001 From: ellyx13 Date: Sat, 8 Jun 2024 06:27:19 +0000 Subject: [PATCH 1/5] fix (typing): Add params abc recursive_guard in pydantic v1 for python 3.12 --- pydantic/v1/typing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pydantic/v1/typing.py b/pydantic/v1/typing.py index a690a053a26..d2e3f4ad0ed 100644 --- a/pydantic/v1/typing.py +++ b/pydantic/v1/typing.py @@ -63,7 +63,7 @@ def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # Even though it is the right signature for python 3.9, mypy complains with # `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast... - return cast(Any, type_)._evaluate(globalns, localns, set()) + return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) if sys.version_info < (3, 9): From 4dd82bc54066c3bcce8ed321cb4596b6e7370da8 Mon Sep 17 00:00:00 2001 From: ellyx13 Date: Sat, 8 Jun 2024 14:21:36 +0000 Subject: [PATCH 2/5] Fix missing recursive_guard parameter in Pydantic v1 for Python 3.9 to 3.12.3 --- pydantic/v1/typing.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pydantic/v1/typing.py b/pydantic/v1/typing.py index d2e3f4ad0ed..f5f99ee33de 100644 --- a/pydantic/v1/typing.py +++ b/pydantic/v1/typing.py @@ -57,13 +57,20 @@ def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: return type_._evaluate(globalns, localns) - + +elif sys.version_info <= (3, 12, 3): + + def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: + # For Python 3.9 to 3.12.3 and fix the error below + # TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' + return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) + else: def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # Even though it is the right signature for python 3.9, mypy complains with # `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast... - return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) + return cast(Any, type_)._evaluate(globalns, localns, set()) if sys.version_info < (3, 9): From 19c128ece842eb54302e09636c79ee6c71bdb8fd Mon Sep 17 00:00:00 2001 From: ellyx13 Date: Sat, 8 Jun 2024 15:41:51 +0000 Subject: [PATCH 3/5] Fix missing recursive_guard parameter in Pydantic v1 for 3.12.4+ --- pydantic/v1/typing.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/pydantic/v1/typing.py b/pydantic/v1/typing.py index f5f99ee33de..558b24545bf 100644 --- a/pydantic/v1/typing.py +++ b/pydantic/v1/typing.py @@ -54,23 +54,21 @@ if sys.version_info < (3, 9): - def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: return type_._evaluate(globalns, localns) -elif sys.version_info <= (3, 12, 3): - - def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: - # For Python 3.9 to 3.12.3 and fix the error below - # TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' - return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) - -else: - +elif sys.version_info < (3, 12, 4): def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # Even though it is the right signature for python 3.9, mypy complains with # `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast... return cast(Any, type_)._evaluate(globalns, localns, set()) + +else: + def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: + # For 3.12.4+ provide a default `recursive_guard` to resolve: + # TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' + + return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) if sys.version_info < (3, 9): From 59c770c8bc3e450e164421b5b0ab2b3e4f30123c Mon Sep 17 00:00:00 2001 From: ellyx13 Date: Sat, 8 Jun 2024 16:59:07 +0000 Subject: [PATCH 4/5] Fix lint failure in CI --- pydantic/v1/typing.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pydantic/v1/typing.py b/pydantic/v1/typing.py index 558b24545bf..5075f97f23c 100644 --- a/pydantic/v1/typing.py +++ b/pydantic/v1/typing.py @@ -56,18 +56,17 @@ if sys.version_info < (3, 9): def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: return type_._evaluate(globalns, localns) - + elif sys.version_info < (3, 12, 4): def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # Even though it is the right signature for python 3.9, mypy complains with # `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast... return cast(Any, type_)._evaluate(globalns, localns, set()) - + else: def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # For 3.12.4+ provide a default `recursive_guard` to resolve: # TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' - return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) From 68458d0824c3742b0490f8981b1cac67a177ba07 Mon Sep 17 00:00:00 2001 From: Sydney Runkle <54324534+sydney-runkle@users.noreply.github.com> Date: Sun, 9 Jun 2024 15:35:56 -0500 Subject: [PATCH 5/5] Attempt sugested fix --- pydantic/v1/typing.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/pydantic/v1/typing.py b/pydantic/v1/typing.py index 5075f97f23c..c435fb11528 100644 --- a/pydantic/v1/typing.py +++ b/pydantic/v1/typing.py @@ -57,17 +57,13 @@ def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: return type_._evaluate(globalns, localns) -elif sys.version_info < (3, 12, 4): +else: def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: # Even though it is the right signature for python 3.9, mypy complains with # `error: Too many arguments for "_evaluate" of "ForwardRef"` hence the cast... - return cast(Any, type_)._evaluate(globalns, localns, set()) - -else: - def evaluate_forwardref(type_: ForwardRef, globalns: Any, localns: Any) -> Any: - # For 3.12.4+ provide a default `recursive_guard` to resolve: + # Note 3.13/3.12.4+ made `recursive_guard` a kwarg, so name it explicitly to avoid: # TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' - return cast(Any, type_)._evaluate(globalns, localns, set(), recursive_guard=set()) + return cast(Any, type_)._evaluate(globalns, localns, recursive_guard=set()) if sys.version_info < (3, 9):