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

[3.12] gh-114053: Fix bad interaction of PEP-695, PEP-563 and get_type_hints (#118009) #118104

Merged
merged 1 commit into from
Apr 19, 2024

Conversation

AlexWaygood
Copy link
Member

@AlexWaygood AlexWaygood commented Apr 19, 2024

…`get_type_hints`` (python#118009)

(cherry-picked from commit 1e3e7ce)

Co-authored-by: Jelle Zijlstra <[email protected]>
@AlexWaygood AlexWaygood enabled auto-merge (squash) April 19, 2024 13:31
@AlexWaygood AlexWaygood merged commit 5430f61 into python:3.12 Apr 19, 2024
29 checks passed
@AlexWaygood AlexWaygood deleted the backport-114053-312 branch April 19, 2024 13:41
AA-Turner pushed a commit to sphinx-doc/sphinx that referenced this pull request Apr 23, 2024
Python has recently [1] changed the signature of `_evaluate` for forward references
because of type parameters. The change affects 3.13, and was backported to 3.12.4.

[1]: python/cpython#118104
vfazio added a commit to vfazio/pydantic that referenced this pull request Jun 10, 2024
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 accomodate 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 <[email protected]>
vfazio added a commit to vfazio/pydantic that referenced this pull request Jun 10, 2024
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 <[email protected]>
@dimaqq
Copy link
Contributor

dimaqq commented Aug 1, 2024

This change causes a regression in some, admittedly rather old code.
Discussion is here: https://discuss.python.org/t/3-12-3-3-12-4-regression-deep-rabbit-hole-warning/59584/12

@AlexWaygood
Copy link
Member Author

This change causes a regression in some, admittedly rather old code. Discussion is here: discuss.python.org/t/3-12-3-3-12-4-regression-deep-rabbit-hole-warning/59584/12

Sorry to hear that. It's pretty unclear to me what exactly the regression is from skimming that Discourse thread, however, and I'm a little low on time right now. Would you be able to create an issue with a minimal, reproducible example?

@dimaqq
Copy link
Contributor

dimaqq commented Aug 2, 2024

I have a rather small MRE here: https://github.com/dimaqq/MRE-sphinx-PurePath

  • 3 small user files
  • uses Sphinx 6.2.1 + autodoc + basic extensions

I haven't gotten deep into Sphinx and how it uses the type system, there would probably be a lot to learn there...

MRE summary

Given this code:

import typing
from pathlib import PurePath
from typing import BinaryIO, Optional, TextIO, Union

class Container:
    """blah"""

    # This is OK (assuming intersphinx is set up)
    def another(self, path: Union[str, PurePath], *, encoding: Optional[str] = 'utf-8'):
        """a docstring"""

    # In the type overload specifically, the `path` argument type is broken under py 3.12.4
    @typing.overload
    def pull(self, path: Union[str, PurePath], *, encoding: str = 'utf-8') -> TextIO: ...

    # Sphinx seems to ignore this signature if there is a type overload
    def pull(self, path: Union[str, PurePath], *, encoding: Optional[str] = 'utf-8'):
        """a docstring"""

Trying to build docs for this code with Sphinx 6.2.1 works under py 3.12.3 and fails under 3.12.4, whith this PR being the breaking change (confirmed by git bisect).

@dimaqq
Copy link
Contributor

dimaqq commented Aug 2, 2024

Daniel has tracked it down to function signature change for ForwardRef._evaluate here:

https://discuss.python.org/t/3-12-3-3-12-4-regression-deep-rabbit-hole-warning/59584/14

Whether the change is required or a regression is something I’m not qualified to have an opinion on, and will gladly leave to Python devs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants