You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
locally imported modules are unaccessible in lambdas in pdb #76987
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=Nonecreated_at=<Date2018-02-09.09:47:46.402>labels= ['type-bug']
title='locally imported modules are unaccessible in lambdas in pdb'updated_at=<Date2018-02-11.20:46:57.026>user='https://bugs.python.org/YuriKanivetsky'
When you run it and try to evaluate (lambda: re.findall('a', 'aaa'))(), you get:
['a', 'a', 'a']
> /home/yuri/_/1.py(7)f()
-> print('test')
(Pdb) (lambda: re.findall('a', 'aaa'))()
*** NameError: name 're' is not defined
(Pdb) import re
(Pdb) (lambda: re.findall('a', 'aaa'))()
*** NameError: name 're' is not defined
(Pdb)
>>> c =compile("(lambda: re.findall('a', 'aaa'))()", "<stdin>", "single")
>>> import re as rea
>>> exec(c, None, {'re': rea})
NameError: name 're' is not defined.
Seeing disassembly of the compiled code, it used LOAD_GLOBAL to get re. This seems to be the problem.
nitishch commented on Feb 11, 2018
nitishchmannequin
Mannequin
More actions
Sorry. I didn't finish my last message. Is the behaviour described in that message a bug? If yes, that would explain the original behaviour. If no, why not?
Activity
YuriKanivetsky commentedon Feb 9, 2018
Consider the following script:
When you run it and try to evaluate
(lambda: re.findall('a', 'aaa'))(), you get:With the commented out breakpoint it works:
Also it works with uncommented global import and second breakpoint:
From what I can see the issue occurs when there's no
reinglobalsargument here: https://github.com/python/cpython/blob/v3.6.4/Lib/pdb.py#L376I've run into it when trying to grep some object's attribute names, like:
nitishch commentedon Feb 11, 2018
This can be traced back to the following issue:
Seeing disassembly of the compiled code, it used LOAD_GLOBAL to get re. This seems to be the problem.
nitishch commentedon Feb 11, 2018
Sorry. I didn't finish my last message. Is the behaviour described in that message a bug? If yes, that would explain the original behaviour. If no, why not?
gaogaotiantian commentedon May 6, 2024
Fixed by #111094