From fefa57fa4cdaf717f90e7294343b5f0efda30fbd Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Fri, 4 Oct 2024 02:39:06 -0400 Subject: [PATCH] cherry-pick upstream: fix function overload of Library.simple_tag --- django-stubs/template/library.pyi | 2 +- tests/typecheck/template/test_library.yml | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/django-stubs/template/library.pyi b/django-stubs/template/library.pyi index fddeaa381..f9d146723 100644 --- a/django-stubs/template/library.pyi +++ b/django-stubs/template/library.pyi @@ -29,7 +29,7 @@ class Library: @overload def filter(self, name: str | None = None, filter_func: None = None, **flags: Any) -> Callable[[_C], _C]: ... @overload - def simple_tag(self, func: _C) -> _C: ... + def simple_tag(self, func: _C, takes_context: bool | None = None, name: str | None = None) -> _C: ... @overload def simple_tag(self, takes_context: bool | None = None, name: str | None = None) -> Callable[[_C], _C]: ... def inclusion_tag( diff --git a/tests/typecheck/template/test_library.yml b/tests/typecheck/template/test_library.yml index b3fd4dde0..2be31d925 100644 --- a/tests/typecheck/template/test_library.yml +++ b/tests/typecheck/template/test_library.yml @@ -57,6 +57,16 @@ reveal_type(some_function) # N: Revealed type is "def (value: builtins.int) -> builtins.int" +- case: register_simple_tag_via_call + main: | + from django import template + register = template.Library() + + def f(s: str) -> str: + return s * 2 + + reveal_type(register.simple_tag(f, name='double')) # N: Revealed type is "def (s: builtins.str) -> builtins.str" + - case: register_tag_no_args main: | from django import template