Skip to content

Commit

Permalink
resolver: code comments for CurrentEnvironment
Browse files Browse the repository at this point in the history
  • Loading branch information
spookylukey committed Jan 29, 2019
1 parent 628ea31 commit 59292d6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions fluent.runtime/fluent/runtime/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@
class CurrentEnvironment(object):
# The parts of ResolverEnvironment that we want to mutate (and restore)
# temporarily for some parts of a call chain.

# The values of attributes here must not be mutated, they must only be
# swapped out for different objects using `modified` (see below).

# For Messages, VariableReference nodes are interpreted as external args,
# but for Terms they are the values explicitly passed using CallExpression
# syntax. So we have to be able to change 'args' for this purpose.
args = attr.ib()
# This controls whether we need to report an error if a VariableReference
# refers to an arg that is not present in the args dict.
error_for_missing_arg = attr.ib(default=True)


Expand All @@ -58,8 +67,8 @@ def modified(self, **replacements):
Context manager that modifies the 'current' attribute of the
environment, restoring the old data at the end.
"""
# CurrentEnvironment only has immutable args at the moment, so the
# shallow copy returned by attr.evolve is fine.
# CurrentEnvironment only has args that we never mutate, so the shallow
# copy returned by attr.evolve is fine (at least for now).
old_current = self.current
self.current = attr.evolve(old_current, **replacements)
yield self
Expand Down

0 comments on commit 59292d6

Please sign in to comment.