Template Analysis
TemplateAnalysis
TemplateAnalysis(
*,
variables: Refs,
local_variables: Refs,
global_variables: Refs,
failed_visits: NameRefs,
unloadable_partials: NameRefs,
filters: NameRefs,
tags: NameRefs
)
The result of analyzing a template using BoundTemplate.analyze
.
Each of the following properties is a dictionary mapping variable, tag or filter
names to a list of tuples. Each tuple holds the location of a reference to the name
as (template name, line number). If a name is referenced multiple times, it will
appear multiple times in the list. If a name is referenced before it is "assigned",
it will appear in local_variables
and global_variables
.
ATTRIBUTE | DESCRIPTION |
---|---|
variables |
All referenced variables, whether they are in scope or not.
Including references to names such as
TYPE:
|
local_variables |
Template variables that are added to the template local scope, whether they are subsequently used or not.
TYPE:
|
global_variables |
Template variables that, on the given line number and "file", are out of scope or are assumed to be "global". That is, expected to be included by the application developer rather than a template author.
TYPE:
|
failed_visits |
Names of AST
TYPE:
|
unloadable_partials |
Names or identifiers of partial templates that
could not be loaded. This will be empty if
TYPE:
|
filters |
All filters found during static analysis.
TYPE:
|
tags |
All tags found during static analysis.
|
ReferencedVariable
Bases: str
A str subclass for variables found during static analysis.
Refs
module-attribute
A mapping of template variables to their (template_name, line_number) locations.
NameRefs
module-attribute
A mapping of template, tag or filter names to (template_name, lineno) locations.
ContextualTemplateAnalysis
ContextualTemplateAnalysis(
*,
all_variables: Dict[str, int],
local_variables: Dict[str, int],
undefined_variables: Dict[str, int],
filters: Dict[str, int]
)
The result of analyzing a template using BoundTemplate.analyze_with_context
.
Each of the following properties is a dictionary mapping variable or filter names to the number of times that variable was referenced.
ATTRIBUTE | DESCRIPTION |
---|---|
all_variables |
All variables references along a path through the template's syntax tree.
TYPE:
|
local_variables |
The names of variables assigned using the
built-in
TYPE:
|
undefined_variables |
The names of variables that could not be
resolved. If a name is referenced before it is assigned, it will appear in
TYPE:
|
filters |
Names of filters found during contextual analysis.
TYPE:
|
TagAnalysis
TagAnalysis(
*,
env: Environment,
name: str,
tokens: List[Token],
inner_tags: Optional[InnerTagMap] = None
)
The result of analyzing a template's tags with Environment.analyze_tags()
.
Each of the following properties maps tag names to a list of their locations. Locations are (template_name, line_number) tuples.
Note that raw
tags are not included at all. The lexer converts them to text
tokens before we get a chance to analyze them.
Also be aware that reported unexpected_tags
don't handle the possibility of an
"inner" tag appearing in a partial template (using {% include %}
), where
appropriate enclosing block tags are in the parent template.
ATTRIBUTE | DESCRIPTION |
---|---|
all_tags |
A mapping of all tags to their locations. Includes "end", "inner" and unknown tags.
|
tags |
A mapping of tag names to their locations. Excludes "end" and "inner" tags.
|
unclosed_tags |
Block tags that don't have a matching "end" tag.
|
unexpected_tags |
Inner tags that are not properly enclosed by appropriate
block tags. For example, an
|
unknown_tags |
Tags that are unknown to the environment.
|