-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Open
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
inspect.getfullargspec isn't compatible with 3.14 signatures that depend on deferred evaluation of annotations, and doesn't expose an argument to pass through annotationlib.Format.FORWARDREF to prevent the failure.
import inspect
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from collections.abc import Iterable
def func(a: Iterable):
return
inspect.getfullargspec(func)Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py", line 1261, in getfullargspec
sig = _signature_from_callable(func,
follow_wrapper_chains=False,
skip_bound_arg=False,
sigcls=Signature,
eval_str=False)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py", line 2502, in _signature_from_callable
return _signature_from_function(sigcls, obj,
skip_bound_arg=skip_bound_arg,
globals=globals, locals=locals, eval_str=eval_str,
annotation_format=annotation_format)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py", line 2325, in _signature_from_function
annotations = get_annotations(func, globals=globals, locals=locals, eval_str=eval_str,
format=annotation_format)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/annotationlib.py", line 890, in get_annotations
ann = _get_dunder_annotations(obj)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/annotationlib.py", line 1059, in _get_dunder_annotations
ann = getattr(obj, "__annotations__", None)
File "<stdin>", line 1, in __annotate__
def func(a: Iterable):
^^^^^^^^
NameError: name 'Iterable' is not defined
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
inspect.getfullargspec(func)
~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/inspect.py", line 1271, in getfullargspec
raise TypeError('unsupported callable') from ex
TypeError: unsupported callableI know getfullargspec() is threatened with deprecation (#108901, #76371), but over at Django we're going to need to build a "safe" version of this function (or migrate away from it entirely) unless an upstream patch makes more sense.
I presume that's either:
- always passing through
annotationlib.Format.FORWARDREFto inspect.Signature - exposing an argument
Defensively always using FORWARDREF or similar seems simplest. Happy to provide a PR.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15new features, bugs and security fixesnew features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error