#25422: Annotations in tag functions crash
---------------------------------+--------------------
     Reporter:  krallin          |      Owner:  nobody
         Type:  Uncategorized    |     Status:  new
    Component:  Template system  |    Version:  1.8
     Severity:  Normal           |   Keywords:
 Triage Stage:  Unreviewed       |  Has patch:  0
Easy pickings:  0                |      UI/UX:  0
---------------------------------+--------------------
 Using function annotations in a function decorated with e.g.
 {{{simple_tag}}} throws an error:

 {{{#!python
 ======================================================================
 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,

--
Ticket URL: <https://code.djangoproject.com/ticket/25422>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.550845c0d55ab58a066b4082a8d837bc%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to