-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Fixed #36712 -- Added inspect.signature to avoid type and value errors #20069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
I guess simply using from django.utils.version import PY314
if PY314:
import annotationlib
# ...
if PY314:
sig = inspect.signature(func, annotation_format=annotationlib.Format.FORWARDREF)
else:
sig = inspect.signature(func)
alen = len(sig.parameters)
non_default_params = [
p for p in sig.parameters.values() if p.default is p.empty
]
dlen = alen - len(non_default_params)could work. A test case could probably be from typing import TYPE_CHECKING
from django.utils.version import PY314
if TYPE_CHECKING:
from django.utils.safestring import SafeText
class SomeTestCase(UnitTest):
@unittest.skipUnless(PY314, "Deferred annotations are Python 3.14+ only")
def test_register_filter_deferred_annotations(self):
register = template.Library()
@register.filter("example")
def example_filter(value: str) -> SafeText:
return escape(value)
# Inspection during register fails with deferred annotations with python 3.14+
# TODO: Maybe check if filter can be used |
|
Thanks for your suggestions, i implemented and tested again these changes with other python versions, it seems ok for now, but if i need to do other improvements, im here to help |
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates. Left a couple tips.
|
Thanks for the updates @AugustoPontes1. Re-reading the issue, I'm realizing we have similar issues cropping up in several more places (you can grep for where else we're using I think we're going to need to factor out a helper for this, and just unit test that. But an upstream patch would be simpler. I'm going to wait a few days to see if any responds on python/cpython#141560. |
No problem, i also saw some PRs opened on the cpython repo that are talking about this problem, but they discussed this problem a long time ago, and from what i saw, they didnt get a solution for this, and you remembered well that there are other modules on django that uses the |
Trac ticket number
ticket-#36712
Branch description
Using the django 5.12 version with python 3.14, when you add a templatetag with deferred annotations, a name and value error raises, this PR gives a suggestion to fix this issue
Checklist
mainbranch.