Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/core/IronPython/Runtime/Exceptions/TraceBack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ public FunctionCode f_code {

public object f_builtins {
get {
return _context.LanguageContext.BuiltinModuleDict;
// a frame created by the trace listener has no context of its own, but the listener knows the language context
PythonContext context = _context?.LanguageContext ?? _traceAdapter.PythonContext;
return context.BuiltinModuleDict;
}
}

Expand Down
14 changes: 14 additions & 0 deletions tests/suite/modules/system_related/test_sys.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,20 @@ def test_settrace_Xtracing_module_frame(self):
out = subprocess.check_output([sys.executable, '-X:Tracing', '-c', code])
self.assertEqual(out.strip(), b"['<module>', 'g']")

def test_settrace_f_builtins(self):
# The frame of a traced function has the same builtins as the frame of code that is not traced
import builtins
def g():
return sys._getframe(0).f_builtins

sys.settrace(lambda *args: None)
try:
traced = g()
finally:
sys.settrace(None)
self.assertIs(traced, builtins.__dict__)
self.assertIs(sys._getframe(0).f_builtins, builtins.__dict__)

@skipUnlessIronPython()
@unittest.expectedFailure # dummy getrefcount removed in https://github.com/IronLanguages/ironpython3/pull/577
def test_getrefcount(self):
Expand Down
Loading