Skip to content

inspect.getfullargspec isn't ready for deferred evaluation of annotations #141560

Closed

Description

@jacobtylerwalls

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 callable

I 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.FORWARDREF to 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

Activity

  1. added
    type-bug
    on Nov 14, 2025
  2. anaghaaaaa9 commented on Nov 14, 2025

    @anaghaaaaa9

    Hey i would like to start working on this, can I take up this issue and start working ?

  3. added
    stdlib
    on Nov 14, 2025
  4. picnixz commented on Nov 14, 2025

    @picnixz
    Member

    We first need to assess whether this is an issue or not and how to address it. cc @JelleZijlstra

  5. changed the title [-][3.14] `inspect.getfullargspec` isn't ready for deferred evaluation of annotations[/-] [+]`inspect.getfullargspec` isn't ready for deferred evaluation of annotations[/+] on Nov 14, 2025
  6. added
    3.14
    3.15
    on Nov 14, 2025
  7. anaghaaaaa9 commented on Nov 14, 2025

    @anaghaaaaa9

    sure , i will review the codebase and keep an eye on the issue. If it requires a fix i will be ready to contribute

  8. picnixz commented on Nov 14, 2025

    @picnixz
    Member

    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 easy label.

  9. JelleZijlstra commented on Nov 15, 2025

    @JelleZijlstra
    Member

    We do need to change something here. Perhaps the most consistent way to do it would have been to make inspect.Parameter.annotation and inspect.FullArgSpec.annotation also lazily evaluated, but I didn't think of that for 3.14.

    Other options include adding an annotation_format parameter to fullargspec, 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 (or inspect.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.

  10. 3 remaining items

  11. MRigal commented on May 6, 2026

    @MRigal

    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...

  12. JelleZijlstra commented on May 6, 2026

    @JelleZijlstra
    Member

    Sorry I forgot about this one!

    I am preparing a PR to add an annotation_format parameter 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 getfullargspec returns a namedtuple, can't really smuggle internal hidden data into that).

  13. MRigal commented on May 6, 2026

    @MRigal

    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.

  14. JelleZijlstra commented on May 6, 2026

    @JelleZijlstra
    Member

    Why not as FORWARDREF per default? Although that would be a (not so?) breaking change.

    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.

  15. added a commit that references this issue on May 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.143.15stdlibtopic-typingtype-bug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions