-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Conversation
…`get_type_hints`` (python#118009) (cherry-picked from commit 1e3e7ce) Co-authored-by: Jelle Zijlstra <[email protected]>
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
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]>
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]>
This change causes a regression in some, admittedly rather old code. |
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? |
I have a rather small MRE here: https://github.com/dimaqq/MRE-sphinx-PurePath
I haven't gotten deep into Sphinx and how it uses the type system, there would probably be a lot to learn there... MRE summaryGiven 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). |
Daniel has tracked it down to function signature change for 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. |
(cherry-picked from commit 1e3e7ce)
Co-authored-by: Jelle Zijlstra [email protected]
📚 Documentation preview 📚: https://cpython-previews--118104.org.readthedocs.build/