Skip to content
Myr

exclude globals from find_undeclared_variables

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Brendan · committed by David Lord · parent c5f1fd3 · Browse files · 3 files+7 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+7 added−1 removed

  • tests:+4 added−0 removed
  • other:+3 added−1 removed

3 files+7 added−1 removed

modified:jinja2/meta.py+1 added-1 removed
27 unmodified lines
28 def enter_frame(self, frame):29 """Remember all undeclared identifiers."""30 CodeGenerator.enter_frame(self, frame)31 for _, (action, param) in iteritems(frame.symbols.loads):32 if action == 'resolve':32 if action == 'resolve' and param not in self.environment.globals:33 self.undeclared_identifiers.add(param)343536def find_undeclared_variables(ast):
70 unmodified lines
modified:tests/test_api.py+4 added
119 unmodified lines
120 '{% endfor %}')121 x = meta.find_undeclared_variables(ast)122 assert x == set(['bar', 'seq', 'muh'])123124 ast = env.parse('{% for x in range(5) %}{{ x }}{% endfor %}{{ foo }}')125 x = meta.find_undeclared_variables(ast)126 assert x == set(['foo'])127128 def test_find_refererenced_templates(self, env):129 ast = env.parse('{% extends "layout.html" %}{% include helper %}')130 i = meta.find_referenced_templates(ast)131 assert next(i) == 'layout.html'
234 unmodified lines
modified:CHANGES.rst+2 added
17 unmodified lines
18 and getattr on an undefined object. (`#977`_)19- Allow ``{%+`` syntax (with NOP behavior) when20 ``lstrip_blocks == False`` (`#748`_)21- Added a ``default`` parameter for the ``map`` filter. (`#557`_)22- Exclude environment globals from23 :func:`meta.find_undeclared_variables`. #9312425.. _#557: https://github.com/pallets/jinja/issues/55726.. _#765: https://github.com/pallets/jinja/issues/76527.. _#748: https://github.com/pallets/jinja/issues/748
613 unmodified lines