You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"chameleon.utils.Scope": "dict" methods unreliable in presence of "global" variables #305
Working on the integration of zope.tales expressions with chameleon, I noticed that some expressions use Scope.vars.get. Like other dict methods, this method knows nothing about _root and therefore may miss (some) variables defined with Scope.set_global.
>>> from chameleon.utils import Scope
>>> t = Scope()
>>> l = t.copy()
>>> l.setGlobal("a", "A")
>>> l.get("a")
>>>
I'm not sure I'm completely understanding what needs to be done to fix this.
One possibility:
```
def get(self, key, default=None):
try: return self[key]
except NameError: return default
def __contains__(self, key):
try: self[key]
except NameError: return False
else: return True
```
I am not sure whether the other methods are important. If so,
`keys` could be defined by (for Python 3; for Python 2, the `yield from`
must be replaced and `super` needs parameters and maybe, we
want to ensure that the methods return `list`s):
```
def keys(self):
yield from super().keys()
if hasattr(self, "_root"):
for k in self._root.keys():
if not super().__contains__(k): yield k
```
`values` and `items` could by defined in terms of `keys` and
`__getitem__`.
Malthe Borch wrote at 2022-4-5 22:19 -0700:
***@***.*** did you have a chance to look at the pull request that addresses this? ^^^
I missed that you would like me to review.
It can still take some time (I have other tasks at the moment).
Activity
malthe commentedon Mar 29, 2020
I'm not sure I'm completely understanding what needs to be done to fix this.
d-maurer commentedon Mar 29, 2020
malthe commentedon Apr 6, 2022
@d-maurer did you have a chance to look at the pull request that addresses this? ^^^
d-maurer commentedon Apr 6, 2022
malthe commentedon Dec 12, 2023
This should be fixed with #306.