[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2021-12-13 Thread Irit Katriel
Irit Katriel added the comment: Reproduced on 3.11. -- nosy: +iritkatriel versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8 ___ Python tracker

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2020-10-30 Thread STINNER Victor
STINNER Victor added the comment: Davide Rizzo: > I've just stumbled on the same thing happening on some code that attempts to > use logging on __del__. > (...) > File ".../logging/__init__.py", line 1121, in _open > NameError: name 'open' is not defined This is bpo-26789 which is unrelated

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2019-04-24 Thread Davide Rizzo
Davide Rizzo added the comment: I've just stumbled on the same thing happening on some code that attempts to use logging on __del__. Comparing dir(__builtins__) normally and on shutdown, these are missing: ['copyright', 'credits', 'exit', 'help', 'license', 'open', 'quit'] The traceback of

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2018-01-04 Thread Maciej Urbański
Maciej Urbański added the comment: Reproduced in both v3.6.4 and v3.7.0a3 -- nosy: +rooter versions: +Python 3.6, Python 3.7 ___ Python tracker

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2017-07-08 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: The interpreter makes a copy of the builtins module dict at startup and restores it at shutdown. open() is imported from the io module after making the copy, and therefore it is absent in restored module. -- nosy: +haypo, pitrou, serhiy.storchaka

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2016-03-11 Thread reidfaiv
reidfaiv added the comment: def __exit__(self, type_, value, tb): print('__exit__') # print() is also built-in, but works print(sorted(builtins.__dict__.keys())) f = open('test.log', 'wt') # <-- NameError: name 'open' is not defined f.close() I will

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2016-03-10 Thread Martin Panter
Martin Panter added the comment: Actually I was a bit hasty in my response last night. NameError indicates that the “open” symbol has been deleted, not just set to None. If you add print(sorted(builtins.__dict__.keys())) inside __exit__() you can verify this is the case. This contradicts my

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2016-03-10 Thread reidfaiv
reidfaiv added the comment: Indeed, explicitly closing generator helps, following works: def run(**kwargs): g = event_gen(**kwargs) r = next(g) g.close() r() Thanks! Do you want to keep this issue open for investigation? -- ___

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2016-03-10 Thread Martin Panter
Martin Panter added the comment: What is probably happening here is how garbage collection works at the interpreter exit. It is sort of mentioned in the warning at . The variable g is an iterator for event_gen(), and it is

[issue26528] NameError for built in function open when re-raising stored exception from yielded function

2016-03-10 Thread reidfaiv
New submission from reidfaiv: Builtin open() gets NameError) in context manager __exit__ in case: * context manager yielding records * we return another generator when consuming these and * second generator raises, catches, stores and re-raises an excption Reduced down code looks like this: