New submission from Robert Haschke <[email protected]>:
The attached file implements a custom dict-like class (MyDict) as a minimal
example of code I am using in a larger codebase.
Before you ask, why I reimplemented a dict-like object: The real code base
employs a hierarchical dict, referencing recursively to the parent dict, if a
key cannot be found in the current dict.
The main code of the file defines two entries/variables for this dict:
symbols = MyDict()
symbols['abc'] = '[1, 2, 3]'
symbols['xyz'] = 'abc + abc'
and eval_text('xyz', symbols) should evaluate to the python expression as you
would have evaluated those variables in a python interpreter.
While this works for the first given expression (above), it fails for this one:
symbols['xyz'] = '[abc[i]*abc[i] for i in [0, 1, 2]]'
raising NameError: name 'abc' is not defined.
The same code works perfectly in python 2.7. Hence, I assume this is a bug in
python3.
----------
files: buggy.py
messages: 377616
nosy: Robert Haschke
priority: normal
severity: normal
status: open
title: python3 fails to use custom dict-like object as symbols in eval()
versions: Python 3.8
Added file: https://bugs.python.org/file49476/buggy.py
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41878>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com