Skip to content
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

CPython 3.13 warns on FutureRef._evaluate/typing._eval_type not passing type_params #9613

Closed
4 of 15 tasks
Tracked by #9753
vfazio opened this issue Jun 10, 2024 · 13 comments
Closed
4 of 15 tasks
Tracked by #9753
Assignees
Labels
bug V1 Bug related to Pydantic V1.X bug V2 Bug related to Pydantic V2

Comments

@vfazio
Copy link

vfazio commented Jun 10, 2024

Initial Checks

  • I have searched GitHub for a duplicate issue and I'm sure this is something new
  • I have searched Google & StackOverflow for a solution and couldn't find anything
  • I have read and followed the docs and still think this is a bug
  • I am confident that the issue is with pydantic (not my code, or another library in the ecosystem like FastAPI or mypy)

Description

See upstream pull request python/cpython#118695

And discussion: python/cpython#118418

The current call pattern will be disallowed starting in CPython 3.15 based on the warning.

Example Code

No response

Python, Pydantic & OS Version

Python 3.13

Affected Components

@vfazio vfazio added bug V1 Bug related to Pydantic V1.X pending Awaiting a response / confirmation labels Jun 10, 2024
@vfazio
Copy link
Author

vfazio commented Jun 10, 2024

@sydney-runkle FYI, semi related to #9607

@musicinmybrain
Copy link
Contributor

Note that this can be reproduced with:

$ gh repo clone pydantic/pydantic
$ cd pydantic
$ python3.13 -m venv _e
$ . _e/bin/activate
(_e) $ UNSAFE_PYO3_SKIP_VERSION_CHECK=1 pip install -e .
(_e) $ pip install cloudpickle coverage[toml] dirty-equals eval-type-backport pytest pytest-mock pytest-pretty pytest-examples faker pytest-benchmark pytest-codspeed packaging
(_e) $ python -m pytest
==================================================================================================== ERRORS ====================================================================================================
________________________________________________________________________ ERROR collecting tests/benchmarks/test_discriminated_unions.py ________________________________________________________________________
tests/benchmarks/test_discriminated_unions.py:11: in <module>
    class NestedState(BaseModel):
pydantic/_internal/_model_construction.py:200: in __new__
    set_model_fields(cls, bases, config_wrapper, types_namespace)
pydantic/_internal/_model_construction.py:469: in set_model_fields
    fields, class_vars = collect_model_fields(cls, bases, config_wrapper, types_namespace, typevars_map=typevars_map)
pydantic/_internal/_fields.py:132: in collect_model_fields
    type_hints = get_cls_type_hints_lenient(cls, types_namespace)
pydantic/_internal/_typing_extra.py:231: in get_cls_type_hints_lenient
    hints[name] = eval_type_lenient(value, globalns, localns)
pydantic/_internal/_typing_extra.py:243: in eval_type_lenient
    return eval_type_backport(value, globalns, localns)
pydantic/_internal/_typing_extra.py:259: in eval_type_backport
    return typing._eval_type(  # type: ignore
/usr/lib64/python3.13/typing.py:470: in _eval_type
    _deprecation_warning_for_no_type_params_passed("typing._eval_type")
/usr/lib64/python3.13/typing.py:450: in _deprecation_warning_for_no_type_params_passed
    warnings.warn(depr_message, category=DeprecationWarning, stacklevel=3)
E   DeprecationWarning: Failing to pass a value to the 'type_params' parameter of 'typing._eval_type' is deprecated, as it leads to incorrect behaviour when calling typing._eval_type on a stringified annotation that references a PEP 695 type parameter. It will be disallowed in Python 3.15.
[…]
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Interrupted: 17 errors during collection !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Results (2.24s):
        17 errors

@musicinmybrain
Copy link
Contributor

Note also that #9613 (comment), above, reproduces this with the latest Pydantic v2, so this is not only a Pydantic v1 issue.

@musicinmybrain musicinmybrain mentioned this issue Jun 15, 2024
13 tasks
@samuelcolvin samuelcolvin added bug V2 Bug related to Pydantic V2 and removed pending Awaiting a response / confirmation labels Jun 16, 2024
@vfazio
Copy link
Author

vfazio commented Jun 16, 2024

Anything calling typing._eval_type or typing.ForwardRef._evaluate will throw these deprecation warnings i believe so maybe both versions?

@samuelcolvin
Copy link
Member

yup, makes sense. Ideally we should find a way to remove their use, at least from V2.

In V1 we can do something hackier.

@sydney-runkle
Copy link
Member

@vfazio,

Are you able to repro this on main? Do we need to leave this open as we look to explicitly support 3.13 for v2?

@vfazio
Copy link
Author

vfazio commented Jun 18, 2024

@vfazio,

Are you able to repro this on main? Do we need to leave this open as we look to explicitly support 3.13 for v2?

@sydney-runkle It looks like @musicinmybrain tested this on main #9613 (comment). If you want me to reproduce, I can set some time aside maybe tomorrow.

If v1 won't have 3.13 support, we can maybe drop the bug V1 label and just leave the v2 label

@sydney-runkle
Copy link
Member

sydney-runkle commented Jun 18, 2024

All good, let's leave this open then, thanks @musicinmybrain!

Note also that #9613 (comment), above, reproduces this with the latest Pydantic v2, so this is not only a Pydantic v1 issue.

I read this and assumed you were using v2.7.4, my apologies!

@sydney-runkle
Copy link
Member

@vfazio,

Any interest in helping us with another v1 patch here? I've got a draft PR up to start adding support for 3.13 explicitly in v2, but we'll have to do this _eval_type fix in the v1 code...

@vfazio
Copy link
Author

vfazio commented Jun 25, 2024

Hah, I thought we weren't making changes in v1 to accommodate 3.13. Is there no way to not call into v1 apis for this functionality?

@sydney-runkle
Copy link
Member

Sigh... you and me both. I'll look into this in depth in the morning.

@sydney-runkle
Copy link
Member

@vfazio,

Since this is such a small change, we're going to roll with it. Hopefully nothing else is needed in V1.

@sydney-runkle sydney-runkle mentioned this issue Jun 25, 2024
11 tasks
@sydney-runkle sydney-runkle self-assigned this Jun 25, 2024
@sydney-runkle
Copy link
Member

Closing given that I merged the above, this should be fixed in 2.8!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug V1 Bug related to Pydantic V1.X bug V2 Bug related to Pydantic V2
Projects
None yet
Development

No branches or pull requests

4 participants