Bug report
Bug description:
if typing.TYPE_CHECKING:
from somelib import SomeType
def f(arg: SomeType): ...
inspect.signature(f) # NameError: name 'SomeType' is not defined
Some linters have rules that move imports into TYPE_CHECKING blocks and after this seemingly benign change inspect.signature will unexpectedly fail, even if its caller never cared about annotations.
At the very least, the documentation of inspect.signature should warn about this (currently it only talks about string annotations and makes no mention of Python 3.14 lazy annotations). But perhaps there’s a way of making inspect.signature work without such a surprising behavior, maybe by making some Signature fields lazy.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Bug report
Bug description:
Some linters have rules that move imports into TYPE_CHECKING blocks and after this seemingly benign change inspect.signature will unexpectedly fail, even if its caller never cared about annotations.
At the very least, the documentation of inspect.signature should warn about this (currently it only talks about string annotations and makes no mention of Python 3.14 lazy annotations). But perhaps there’s a way of making inspect.signature work without such a surprising behavior, maybe by making some Signature fields lazy.
CPython versions tested on:
3.14
Operating systems tested on:
Linux