Skip to content
Myr

Changed all sentences with occurrences of subscribing to a similar sentence that uses the word "subscript". And the person that comes up with a less confusing verb for the attribute/item lookup method (that is not lookup!!1) gets an extra THANKS entry.

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

--HG-- branch : trunk

authored by Armin Ronacher · committed by Armin Ronacher · parent 4778bda · Browse files · 3 files+10 added−11 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+10 added−11 removed

  • other:+10 added−11 removed

3 files+10 added−11 removed

modified:docs/templates.rst+4 added-5 removed
57 unmodified lines
58too. How a variable looks like, heavily depends on the application providing59those.6061You can use a dot (``.``) to access attributes of a variable, alternative the62so-called "subscribe" syntax (``[]``) can be used. The following lines do62so-called "subscript" syntax (``[]``) can be used. The following lines do63the same::6465 {{ foo.bar }}66 {{ foo['bar'] }}
6 unmodified lines
73value. What you can do with that kind of value depends on the application74configuration, the default behavior is that it evaluates to an empty string75if printed and that you can iterate over it, but every other operation fails.7677.. _notes-on-subscribing:77.. _notes-on-subscriptions:7879.. admonition:: Implementation8081 The process of looking up attributes and items of objects is called82 "subscribing" an object. For convenience sake ``foo.bar`` in Jinja283 does the following things on the Python layer:81 For convenience sake ``foo.bar`` in Jinja2 does the following things on82 the Python layer:8384 - check if there is an attribute called `bar` on `foo`.85 - if there is not, check if there is an item ``'bar'`` in `foo`.86 - if there is not, return an undefined object.
1024 unmodified lines
modified:jinja2/compiler.py+1 added-1 removed
1272 unmodified lines
1273 self.visit(node.node, frame)1274 self.write(', %r)' % node.attr)12751276 def visit_Getitem(self, node, frame):1277 # slices or integer subscriptions bypass the subscribe1277 # slices or integer subscriptions bypass the getitem1278 # method if we can determine that at compile time.1279 if isinstance(node.arg, nodes.Slice) or \1280 (isinstance(node.arg, nodes.Const) and1281 isinstance(node.arg.value, (int, long))):
109 unmodified lines
modified:jinja2/nodes.py+5 added-5 removed
314 unmodified lines
315class FromImport(Stmt):316 """A node that represents the from import tag. It's important to not317 pass unsafe names to the name attribute. The compiler translates the318 attribute lookups directly into getattr calls and does *not* use the319 subscribe callback of the interface. As exported variables may not319 subscript callback of the interface. As exported variables may not320 start with double underscores (which the parser asserts) this is not a321 problem for regular Jinja code, but if this node is used in an extension322 extra care must be taken.323
258 unmodified lines
582 raise Impossible()583584585class Getitem(Expr):586 """Subscribe an expression by an argument. This node performs a dict587 and an attribute lookup on the object whatever succeeds.588 """586 """Get an attribute or item from an expression and prefer the item."""587 fields = ('node', 'arg', 'ctx')588589 def as_const(self):590 if self.ctx != 'load':
8 unmodified lines
599 return False600601602class Getattr(Expr):605 """Subscribe an attribute."""603 """Get an attribute or item from an expression that is a ascii-only604 bytestring and prefer the attribute.605 """606 fields = ('node', 'attr', 'ctx')607608 def as_const(self):609 if self.ctx != 'load':
197 unmodified lines