[issue34483] eval() raises NameError: name '...' is not defined

2018-08-25 Thread Eric V. Smith


Eric V. Smith  added the comment:

I'll close this. I'm still reviewing the docs on it, and I might open a 
documentation issue once I understand it better.

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

___
Python tracker 

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



[issue34483] eval() raises NameError: name '...' is not defined

2018-08-25 Thread Alex


Alex  added the comment:

Eric, thank you for the clarification. Do you want me to close the ticket?

--

___
Python tracker 

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



[issue34483] eval() raises NameError: name '...' is not defined

2018-08-23 Thread Steven D'Aprano


Change by Steven D'Aprano :


--
nosy: +steven.daprano

___
Python tracker 

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



[issue34483] eval() raises NameError: name '...' is not defined

2018-08-23 Thread Eric V. Smith


Eric V. Smith  added the comment:

I believe you're seeing this: 
https://docs.python.org/3/reference/executionmodel.html#naming-and-binding

See the paragraph that starts with "Class definition blocks and arguments to 
exec() and eval() are special in the context of name resolution", and the 
example that follows it.

Basically, you're running eval() as if it were at class scope. I think (but am 
not positive) that this statement, from the exec() documentation, also applies 
to eval(): "Remember that at module level, globals and locals are the same 
dictionary. If exec gets two separate objects as globals and locals, the code 
will be executed as if it were embedded in a class definition."

If so, then eval()'s docs should reference this, too.

--
nosy: +eric.smith

___
Python tracker 

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



[issue34483] eval() raises NameError: name '...' is not defined

2018-08-23 Thread Alex


New submission from Alex :

Builtin eval() function raises NameError on a valid expression:


--- example of bug on Python 3.4
Python 3.4.5 (default, May 29 2017, 15:17:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1,2,3]
>>> [x for i in x]
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> eval('[x for i in x]', {}, dict(x=x))
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 1, in 
  File "", line 1, in 
NameError: name 'x' is not defined


--- example on Python 2.7 (no bug)
Python 2.7.5 (default, May  3 2017, 07:55:04)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-14)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = [1,2,3]
>>> [x for i in x]
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]
>>> eval('[x for i in x]', {}, dict(x=x))
[[1, 2, 3], [1, 2, 3], [1, 2, 3]]


---

Bug reproduced on:
- Windows 7: Python 3.4, 3.7
- Red Hat Enterprise Linux Server: Python 3.4

Works without errors on:
- Windows 7: Python 2.7
- Red Hat Enterprise Linux Server: Python 2.7

--
components: Interpreter Core
messages: 323965
nosy: alexb
priority: normal
severity: normal
status: open
title: eval() raises NameError: name '...' is not defined
versions: Python 3.4, Python 3.7

___
Python tracker 

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