[issue45862] Anomaly of eval() of list comprehension

2021-11-22 Thread David Pratten

David Pratten  added the comment:

Hi Mark,

Thanks.  

The anomaly is that the print("eg def2", ...)  works.  Should it not fail in 
the same way that print("eg def4", ...) does.

David

On 22/11/2021 7:36:31 PM, Mark Dickinson  wrote:

Mark Dickinson added the comment:

Thanks for the report. The behaviour is by design: see #5242 (especially 
msg81898) for an explanation.

Closing this issue as a duplicate of #5242.

--
nosy: +mark.dickinson
resolution: -> duplicate
stage: -> resolved
status: open -> closed
superseder: -> eval() function in List Comprehension doesn't work

___
Python tracker

___

[755e9508-5fde-465a-ac8e-d82585c103f3]

--

___
Python tracker 
<https://bugs.python.org/issue45862>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue45862] Anomaly of eval() of list comprehension

2021-11-21 Thread David Pratten


New submission from David Pratten :

Hi

Example "eg def2" works but "eg def4" gives an error?

David

```
emp = [
{
"empno": 7839,
"mgr": 0,
"ename": "KING"
},
{
"empno": 7566,
"mgr": 7839,
"ename": "JONES"
},
{
"empno": 7698,
"mgr": 7839,
"ename": "BLAKE"
}
]

a = [e for e in emp if e["mgr"] == 0]
print('eg 1', [b for b in a])
print('eg 2', eval('[b for b in a]'))
print('eg 3', [e for e in emp for b in a if e["mgr"] == b["empno"]])
print('eg 4', eval('[e for e in emp for b in a if e["mgr"] == b["empno"]]'))


def eval_anomaly():
a_anomaly = [e for e in emp if e["mgr"] == 0]
print('eg def1', [b for b in a_anomaly])
print('eg def2', eval('[b for b in a_anomaly]'))
print('eg def3', [e for e in emp for b in a_anomaly if e["mgr"] == 
b["empno"]])
print('eg def4', eval('[e for e in emp for b in a_anomaly if e["mgr"] == 
b["empno"]]'))

eval_anomaly()
```

--
messages: 406743
nosy: david2
priority: normal
severity: normal
status: open
title: Anomaly of eval() of list comprehension
type: behavior
versions: Python 3.9

___
Python tracker 
<https://bugs.python.org/issue45862>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com