Opened 9 years ago
Closed 9 years ago
#25422 closed Bug (fixed)
Type annotations in template tag functions crash
Reported by: | Thomas Orozco | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.8 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Using function annotations in a function decorated with e.g. simple_tag
throws an error:
====================================================================== ERROR: test_annotated_function (template_tests.test_custom.TemplateTagLoadingTests) ---------------------------------------------------------------------- Traceback (most recent call last): File "/Users/thomas/dev/django/tests/template_tests/test_custom.py", line 446, in test_annotated_function Template(ttext) File "/Users/thomas/dev/django/django/template/base.py", line 190, in __init__ self.nodelist = engine.compile_string(template_string, origin) File "/Users/thomas/dev/django/django/template/engine.py", line 261, in compile_string return parser.parse() File "/Users/thomas/dev/django/django/template/base.py", line 341, in parse compiled_result = compile_func(self, token) File "/Users/thomas/dev/django/django/template/defaulttags.py", line 1159, in load lib = get_library(taglib) File "/Users/thomas/dev/django/django/template/base.py", line 1392, in get_library lib = import_library(taglib_module) File "/Users/thomas/dev/django/django/template/base.py", line 1331, in import_library mod = import_module(taglib_module) File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 986, in _gcd_import File "<frozen importlib._bootstrap>", line 969, in _find_and_load File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 673, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 662, in exec_module File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed File "/Users/thomas/dev/django/tests/template_tests/templatetags/annotated_tag_function.py", line 7, in <module> def annotated_tag_function(val: int): File "/Users/thomas/dev/django/django/template/base.py", line 1189, in dec params, varargs, varkw, defaults = getargspec(func) File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/inspect.py", line 1044, in getargspec raise ValueError("Function has keyword-only arguments or annotations" ValueError: Function has keyword-only arguments or annotations, use getfullargspec() API which can support them
I have prepared a failing test case (and will file it in Github after creating this issue). It looks like this is fixed in 1.9 due to https://code.djangoproject.com/ticket/24979
Backporting those changes would probably fix the issue, but if that's not your preferred solution, I'm happy to work on an alternate patch.
Cheers,
Change History (7)
comment:1 by , 9 years ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Summary: | Annotations in tag functions crash → Type annotations in template tag functions crash |
Type: | Uncategorized → Bug |
comment:2 by , 9 years ago
As mentioned in the GitHub issue, this is not actually a Python 3.5 issue (please feel free to let me know what place is more convenient to discuss — here or Github).
Cheers,
comment:4 by , 9 years ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
As Collin mentioned, if it's not a regression, then a fix probably doesn't qualify for a backport per our supported versions policy.
Anyway, we can merge the test to ensure it keeps working from 1.9 and on. Could you send the pull request against master?
comment:5 by , 9 years ago
Oops, I didn't realize this kind of fixes wouldn't qualify for older releases. My bad, apologies!
It does indeed *not* work on Django 1.7 either.
I sent over another PR targeting master (https://github.com/django/django/pull/5307), though by the looks of it (you transitioned to signature), I doubt there will be a regression!
Thanks for the quick response,
Cheers,
comment:7 by , 9 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Sorry, but Django 1.8 won't be getting Python 3.5 support.