[issue23113] Compiler doesn't recognize qualified exec('', {})

2014-12-25 Thread John Firestone

New submission from John Firestone:

Python 2.7.8 (v2.7.8:ee879c0ffa11, Jun 29 2014, 21:07:35) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type help, copyright, credits or license for more information.
 def outer():
... def inner(arg):
... len(arg)
... exec('', {})
... 
  File stdin, line 4
SyntaxError: unqualified exec is not allowed in function 'outer' it contains a 
nested function with free variables
 
 def outer():
... def inner(arg):
... len(arg)
... exec '' in {}
... 


--
components: Interpreter Core
files: bug.py
messages: 233096
nosy: johnf
priority: normal
severity: normal
status: open
title: Compiler doesn't recognize qualified exec('', {})
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file37541/bug.py

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



[issue23113] Compiler doesn't recognize qualified exec('', {})

2014-12-25 Thread John Firestone

John Firestone added the comment:

Sorry. Duplicates 21591

--
status: open - closed

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



[issue15099] exec of function doesn't call __getitem__ or __missing__ on undefined global

2012-06-18 Thread John Firestone

New submission from John Firestone jo...@freenet.de:

exec(source, Dict()) doesn't call Dict().__getitem__ or Dict().__missing__ if 
the source string contains a function and the function references an undefined 
global.

class Dict1(dict):
def __getitem__(self, key):
print '__getitem__', repr(key)
if key == 's':
return None
return dict.__getitem__(self, key)

class Dict2(dict):
def __missing__(self, key):
print '__missing__', repr(key)
return None

source = if 1:
print '  1'
s
def f():
print '  2'
s
print '  3'
f()

print 'Dict1.__getitem__'
try:
exec(source, Dict1())
except NameError as exc_value:
print '  %s: %s' % (exc_value.__class__.__name__, exc_value)

print 'Dict2.__missing__'
try:
exec(source, Dict2())
except NameError as exc_value:
print '%s: %s' % (exc_value.__class__.__name__, exc_value)


Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
 import curiosity
Dict1.__getitem__
  1
__getitem__ 's'
__getitem__ 'f'
  2
NameError: global name 's' is not defined
Dict2.__missing__
  1
__missing__ 's'
  2
NameError: global name 's' is not defined


--
components: Interpreter Core
files: curiosity.py
messages: 163095
nosy: johnf
priority: normal
severity: normal
status: open
title: exec of function doesn't call __getitem__ or __missing__ on undefined 
global
type: behavior
versions: Python 2.7
Added file: http://bugs.python.org/file26041/curiosity.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15099
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15099] exec of function doesn't call __getitem__ or __missing__ on undefined global

2012-06-18 Thread John Firestone

John Firestone jo...@freenet.de added the comment:

I find the behavior inconsistent. As you can see from this example, the 
exec'uted code *does* call the instance's overloaded __getitem__ and 
__missing__ methods when outside a function, but doesn't when inside.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15099
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue15099] exec of function doesn't call __getitem__ or __missing__ on undefined global

2012-06-18 Thread John Firestone

John Firestone jo...@freenet.de added the comment:

Thank you all for the quick and interesting responses!

Here is another example, this time showing a simple
s
sometimes behaves like
globals()['s']
and sometimes doesn't.

class Dict(dict):
def __getitem__(self, key):
if key == 's':
return 'got s'
return dict.__getitem__(self, key)

dct = Dict()
dct['the_dict'] = dct
print 0, id(dct)

source = if 1:
print '1', id(globals()), globals() is the_dict
print ' ', globals()['s']
print ' ', s
def f():
print '2', id(globals()), globals() is the_dict
print ' ', globals()['s']
print ' ', s
print '3'
f()

exec(source, dct)


Python 2.7.3 (v2.7.3:70274d53c1dd, Apr  9 2012, 20:32:06) 
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
 import curiosity2
0 2459928
1 2459928 True
  got s
  got s
2 2459928 True
  got s
 
Traceback (most recent call last):
  File stdin, line 1, in module
  File curiosity2.py, line 22, in module
exec(source, dct)
  File string, line 10, in module
  File string, line 8, in f
NameError: global name 's' is not defined


--
Added file: http://bugs.python.org/file26044/curiosity2.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue15099
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3454] __getitem__() doesn't capture all slices if class inherits from list, tuple or str

2008-07-27 Thread John Firestone

Changes by John Firestone [EMAIL PROTECTED]:


--
components: Interpreter Core
files: getitem_problem.py
nosy: johnf
severity: normal
status: open
title: __getitem__() doesn't capture all slices if class inherits from list, 
tuple or str
type: performance
versions: Python 2.5
Added file: http://bugs.python.org/file10992/getitem_problem.py

___
Python tracker [EMAIL PROTECTED]
http://bugs.python.org/issue3454
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com