Skip to content

Fix is_simple_callable with unresolvable annotations on Python 3.14 - #10069

Merged
auvipy merged 4 commits into
encode:mainfrom
DylanMerigaud:fix-is-simple-callable-py314-annotations
Nov 19, 2026
Merged

auvipy merged 4 commits into
encode:mainfrom
DylanMerigaud:fix-is-simple-callable-py314-annotations

Conversation

@DylanMerigaud

Copy link
Copy Markdown
Contributor

Description

refs #9959

On Python 3.14, inspect.signature() evaluates annotations (PEP 649). Failing case, with SomeType imported under if TYPE_CHECKING::

def get_name(self) -> SomeType: ...
is_simple_callable(obj.get_name)  # NameError

Only parameter kinds and defaults are read, so 3.14+ now uses annotationlib.Format.FORWARDREF. The new test fails on main and passes here; tox passes on 3.13 and 3.14.

I drafted this with Claude Opus 5.5 and read every line of the diff.

inspect.signature() evaluates annotations on Python 3.14 (PEP 649), so a
method annotated with a name imported only under TYPE_CHECKING raised
NameError when used as a serializer field source. Ask for FORWARDREF
annotations instead, as only parameter kinds and defaults are needed.

Refs encode#9959
@auvipy
auvipy self-requested a review October 7, 2026 02:39
Comment thread rest_framework/fields.py Resolved
Comment thread tests/test_fields.py Resolved
The Python version cannot change while the process runs, so the check and
the dict move to a module level SIGNATURE_KWARGS constant.
Cover a parameter annotated with an undefined name, both with a default
(simple callable) and without one (not a simple callable).
@auvipy auvipy added this to the 3.18 milestone Nov 19, 2026
@auvipy
auvipy merged commit 074a63a into encode:main Nov 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants