Repository navigation
Closed
Labels
3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn 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
Linked PRs
Reacted by Matei Dibu and Matthieu Rigal
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixes3.15bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Activity
anaghaaaaa9 commentedon Nov 14, 2025
Hey i would like to start working on this, can I take up this issue and start working ?
picnixz commentedon Nov 14, 2025
We first need to assess whether this is an issue or not and how to address it. cc @JelleZijlstra
[-][3.14] `inspect.getfullargspec` isn't ready for deferred evaluation of annotations[/-][+]`inspect.getfullargspec` isn't ready for deferred evaluation of annotations[/+]anaghaaaaa9 commentedon Nov 14, 2025
sure , i will review the codebase and keep an eye on the issue. If it requires a fix i will be ready to contribute
picnixz commentedon Nov 14, 2025
I do not think it is necessary to review the codebase. I prefer first hearing from Jelle as he is the one who implemented deferred annotations. If you want an easy issue to contribute to, I suggest looking at the issues with the
easylabel.JelleZijlstra commentedon Nov 15, 2025
We do need to change something here. Perhaps the most consistent way to do it would have been to make
inspect.Parameter.annotationandinspect.FullArgSpec.annotationalso lazily evaluated, but I didn't think of that for 3.14.Other options include adding an
annotation_formatparameter tofullargspec, and making it just eat the exception if the annotations can't be evaluated.What I like about the first suggestion is that likely many users of
getfullargspec(orinspect.signature) don't care about the annotations, so if we make them lazily evaluated, they won't have to worry about the problem at all.Fixed #36712 -- Avoided evaluating type annotations in template tag r…
Fixed #36712 -- Evaluated type annotations lazily in template tag reg…
Fixed #36712 -- Evaluated type annotations lazily in template tag reg…
3 remaining items
Fixed #36712 -- Evaluated type annotations lazily in template tag reg…
[6.0.x] Fixed #36712 -- Evaluated type annotations lazily in template…
[5.2.x] Fixed #36712 -- Evaluated type annotations lazily in template…
forwards-port cpython issue 141560 for getfullargspec
forwards-port cpython issue 141560 for getfullargspec
MRigal commentedon May 6, 2026
I find it crazy that Python 3.15 is almost rc and this bug has survived all 3.14 minor versions... Django, SqlAlchemy and many others vendor their own fixed version of getfullargspec...
JelleZijlstra commentedon May 6, 2026
Sorry I forgot about this one!
I am preparing a PR to add an
annotation_formatparameter to getfullargspec; we might still have time to get that into 3.15.The better solution would be to make the various signature/argspec APIs stop eagerly evaluating annotations at all, but I'm not sure that's achievable while maintaining the existing API shape (for example
getfullargspecreturns a namedtuple, can't really smuggle internal hidden data into that).MRigal commentedon May 6, 2026
Hi @JelleZijlstra
Thanks for that and no fingerpointing at anyone doing voluntary work!
It was "just" a remark because it is something broadly used and the consequences is that anyone goes on with "well it's anyway broken python core..."...
Although this might be a separated PR, but I wonder if inspect.signature() and inspect.getfullargspec() should really format annotations as "Format.VALUE" per default. Why not as FORWARDREF per default? Although that would be a (not so?) breaking change.
JelleZijlstra commentedon May 6, 2026
Yes, that's why. I actually suggested this when we were making the main changes for 3.14 but it was rejected because of compatibility. Though that's somewhat relative: you'll only see forwardrefs on code that otherwise wouldn't have worked at all.
gh-141560: Add annotation_format parameter to getfullargspec (#149457)
inspect.getfullargspecstill needsfrom __future__ import annotations#149975 as a duplicate of this issueFixed #36712 -- Evaluated type annotations lazily in template tag reg…
Fixed #36712 -- Evaluated type annotations lazily in template tag reg…