[Django] #36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+

0 views
Skip to first unread message

Django

unread,
Feb 5, 2026, 7:40:48 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
--------------------------+----------------------------------------
Reporter: 93578237 | Type: Bug
Status: new | Component: Core (Other)
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+----------------------------------------
On python 3.14 it fails at least here:
https://github.com/django/django/blob/13299a6203f4bc3e5b2552c96a51ff2b15da3c43/django/contrib/auth/__init__.py#L43

Maybe a new function `signature` should be added to utils/inspect.py
--
Ticket URL: <https://code.djangoproject.com/ticket/36903>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 5, 2026, 7:43:41 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
------------------------------+--------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by 93578237:

Old description:

> On python 3.14 it fails at least here:
> https://github.com/django/django/blob/13299a6203f4bc3e5b2552c96a51ff2b15da3c43/django/contrib/auth/__init__.py#L43
>
> Maybe a new function `signature` should be added to utils/inspect.py

New description:
{{{
import typing as t

if t.TYPE_CHECKING:
from django.http import HttpRequest

from testproject.models import User as UserModel


class AuthenticationBackend(ModelBackend):
def authenticate(
self,
request: HttpRequest | None = None,
username: str | None = None,
password: str | None = None,
**kwargs: t.Any,
) -> UserModel | None: ...
}}}

Maybe a new function `signature` should be added to utils/inspect.py

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:1>

Django

unread,
Feb 5, 2026, 7:44:57 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
------------------------------+--------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by 93578237:

Old description:

> On python 3.14 it fails at least here:
> https://github.com/django/django/blob/13299a6203f4bc3e5b2552c96a51ff2b15da3c43/django/contrib/auth/__init__.py#L43
>
> {{{
> import typing as t
>
> if t.TYPE_CHECKING:
> from django.http import HttpRequest
>
> from testproject.models import User as UserModel
>

> class AuthenticationBackend(ModelBackend):
> def authenticate(
> self,
> request: HttpRequest | None = None,
> username: str | None = None,
> password: str | None = None,
> **kwargs: t.Any,
> ) -> UserModel | None: ...
> }}}
>
> Maybe a new function `signature` should be added to utils/inspect.py

New description:

On python 3.14 it fails at least here:
https://github.com/django/django/blob/13299a6203f4bc3e5b2552c96a51ff2b15da3c43/django/contrib/auth/__init__.py#L43

{{{
import typing as t

from django.contrib.auth.backends import ModelBackend


if t.TYPE_CHECKING:
from django.http import HttpRequest

from testproject.models import User as UserModel


class AuthenticationBackend(ModelBackend):
def authenticate(
self,
request: HttpRequest | None = None,
username: str | None = None,
password: str | None = None,
**kwargs: t.Any,
) -> UserModel | None: ...
}}}

Maybe a new function `signature` should be added to utils/inspect.py

--
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:2>

Django

unread,
Feb 5, 2026, 7:45:11 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
------------------------------+--------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by 93578237:

Old description:

> On python 3.14 it fails at least here:
> https://github.com/django/django/blob/13299a6203f4bc3e5b2552c96a51ff2b15da3c43/django/contrib/auth/__init__.py#L43
>
> {{{
> import typing as t
>
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:3>

Django

unread,
Feb 5, 2026, 9:32:58 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* keywords: => typing, inspect, deferred annotations
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted

Comment:

Thanks, looks like we missed a few in #36696 and #36712.

We need to audit uses of `inspect.signature` with the possible exception
of cases where we are only inspecting Django's own signatures e.g.
`deprecate_posargs()`, but even that is debatable since there is
[https://github.com/django/new-features/issues/23 motion toward] making
gradual explorations of incremental type annotations in Django.
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:4>

Django

unread,
Feb 5, 2026, 9:44:40 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by 93578237):

Would it be possible to backport it to 5.x? I encountered that on 5.2.x.

My proposal is to add the inspect function that passes an additional
annotation_format kwarg if its PY_314
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:5>

Django

unread,
Feb 5, 2026, 9:46:15 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls):

That decision will be made during review, but I'll note that prior related
tickets were backported to 5.2.x.
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:6>

Django

unread,
Feb 5, 2026, 9:51:34 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: (none)
Type: Bug | Status: new
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by 93578237):

I can work on it. Should it be fixed in-place or by reusing a separate
function?
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:7>

Django

unread,
Feb 5, 2026, 10:20:22 AM (7 days ago) Feb 5
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: assigned
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* owner: (none) => 93578237
* status: new => assigned

Comment:

A new function is appealing, since the last time we touched this, we ended
up with bloat like this:

{{{#!py
# As the annotations are not used in any case, inspect the signature
with
# FORWARDREF to leave any deferred annotations unevaluated.
if PY314:
signature = inspect.signature(
func, annotation_format=annotationlib.Format.FORWARDREF
)
else:
signature = inspect.signature(func)
}}}

Now that we're aware of the multiple call sites that matter, DRY-ing this
out makes sense to me.

Thanks for volunteering.
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:8>

Django

unread,
Feb 6, 2026, 3:49:23 AM (6 days ago) Feb 6
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: assigned
Component: Core (Other) | Version: 6.0
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by 93578237):

* has_patch: 0 => 1

--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:9>

Django

unread,
Feb 6, 2026, 1:04:53 PM (6 days ago) Feb 6
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: assigned
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* needs_better_patch: 0 => 1
* version: 6.0 => 5.2

--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:10>

Django

unread,
Feb 9, 2026, 3:18:14 AM (3 days ago) Feb 9
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: assigned
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Accepted
deferred annotations |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by 93578237):

* needs_better_patch: 1 => 0

--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:11>

Django

unread,
Feb 9, 2026, 4:16:43 PM (2 days ago) Feb 9
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: assigned
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution:
Keywords: typing, inspect, | Triage Stage: Ready for
deferred annotations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* stage: Accepted => Ready for checkin

--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:12>

Django

unread,
Feb 10, 2026, 4:52:06 PM (2 days ago) Feb 10
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: closed
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: typing, inspect, | Triage Stage: Ready for
deferred annotations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls <jacobtylerwalls@…>):

* resolution: => fixed
* status: assigned => closed

Comment:

In [changeset:"56ed37e17e5b1a509aa68a0c797dcff34fcc1366" 56ed37e1]:
{{{#!CommitTicketReference repository=""
revision="56ed37e17e5b1a509aa68a0c797dcff34fcc1366"
Fixed #36903 -- Fixed further NameErrors when inspecting functions with
deferred annotations.

Provide a wrapper for safe introspection of user functions on Python
3.14+.

Follow-up to 601914722956cc41f1f2c53972d669ddee6ffc04.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:13>

Django

unread,
Feb 10, 2026, 5:02:00 PM (2 days ago) Feb 10
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: closed
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: typing, inspect, | Triage Stage: Ready for
deferred annotations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"deac58ed822c6cd819e916e6c3d1736c7adfa31e" deac58e]:
{{{#!CommitTicketReference repository=""
revision="deac58ed822c6cd819e916e6c3d1736c7adfa31e"
[6.0.x] Fixed #36903 -- Fixed further NameErrors when inspecting functions
with deferred annotations.

Provide a wrapper for safe introspection of user functions on Python
3.14+.

Follow-up to 601914722956cc41f1f2c53972d669ddee6ffc04.
Backport of 56ed37e17e5b1a509aa68a0c797dcff34fcc1366 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:14>

Django

unread,
Feb 10, 2026, 5:13:42 PM (2 days ago) Feb 10
to django-...@googlegroups.com
#36903: inspect.signature should use FORWARDREF annotation_format for python 3.14+
-------------------------------------+-------------------------------------
Reporter: 93578237 | Owner: 93578237
Type: Bug | Status: closed
Component: Core (Other) | Version: 5.2
Severity: Release blocker | Resolution: fixed
Keywords: typing, inspect, | Triage Stage: Ready for
deferred annotations | checkin
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Jacob Walls <jacobtylerwalls@…>):

In [changeset:"a4999ef1b9790a4c0e793cf0e5c464e9935c3c3a" a4999ef]:
{{{#!CommitTicketReference repository=""
revision="a4999ef1b9790a4c0e793cf0e5c464e9935c3c3a"
[5.2.x] Fixed #36903 -- Fixed further NameErrors when inspecting functions
with deferred annotations.

Provide a wrapper for safe introspection of user functions on Python
3.14+.

Follow-up to 601914722956cc41f1f2c53972d669ddee6ffc04.
Backport of 56ed37e17e5b1a509aa68a0c797dcff34fcc1366 from main.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/36903#comment:15>
Reply all
Reply to author
Forward
0 new messages