8000 Specify recursive_guard as kwarg in FutureRef._evaluate by vfazio · Pull Request #9612 · pydantic/pydantic · GitHub
[go: up one dir, main page]

Skip to content

Specify recursive_guard as kwarg in FutureRef._evaluate #9612

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Specify recursive_guard as kwarg in FutureRef._evaluate
In CPython 3.12.4/3.13, the function signature of `FutureRef._evaluate`
changed such that `recursive_guard` is no longer a positional argument;
it is now keyword only [0][1].

To accommodate this, specify `recursive_guard` as a kwarg. This syntax
is backwards compatible with earlier versions of the function signature.

[0]: python/cpython#118104
[1]: python/cpython#118009

Signed-off-by: Vincent Fazio <vfazio@gmail.com>
  • Loading branch information
vfazio committed Jun 10, 2024
commit 78c04016d0544a19f898af18d31a42b06aebc801
4 changes: 3 additions & 1 deletion pydantic/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ 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())
# Python 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, recursive_guard=set())


if sys.version_info < (3, 9):
Expand Down
0