Skip to content

Commit bc1eaf6

Browse files
committed
resolver: code comments for CurrentEnvironment
1 parent 939c00f commit bc1eaf6

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

fluent.runtime/fluent/runtime/resolver.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,16 @@
4040
class CurrentEnvironment(object):
4141
# The parts of ResolverEnvironment that we want to mutate (and restore)
4242
# temporarily for some parts of a call chain.
43+
44+
# The values of attributes here must not be mutated, they must only be
45+
# swapped out for different objects using `modified` (see below).
46+
47+
# For Messages, VariableReference nodes are interpreted as external args,
48+
# but for Terms they are the values explicitly passed using CallExpression
49+
# syntax. So we have to be able to change 'args' for this purpose.
4350
args = attr.ib()
51+
# This controls whether we need to report an error if a VariableReference
52+
# refers to an arg that is not present in the args dict.
4453
error_for_missing_arg = attr.ib(default=True)
4554

4655

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

0 commit comments

Comments
 (0)