[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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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 (yesterday) 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,
3:49 AM (10 hours ago) 3:49 AM
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,
1:04 PM (1 hour ago) 1:04 PM
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>
Reply all
Reply to author
Forward
0 new messages