Show More
@@ -2345,7 +2345,7 b' class InteractiveShell(SingletonConfigurable):' | |||
|
2345 | 2345 | magic_arg_s = self.var_expand(line, stack_depth) |
|
2346 | 2346 | kwargs = {} |
|
2347 | 2347 | if getattr(fn, "needs_local_scope", False): |
|
2348 |
kwargs['local_ns'] = s |
|
|
2348 | kwargs['local_ns'] = self.user_ns | |
|
2349 | 2349 | |
|
2350 | 2350 | with self.builtin_trap: |
|
2351 | 2351 | args = (magic_arg_s, cell) |
@@ -1127,8 +1127,8 b' python-profiler package from non-free.""")' | |||
|
1127 | 1127 | ns = {} |
|
1128 | 1128 | glob = self.shell.user_ns |
|
1129 | 1129 | # handles global vars with same name as local vars. We store them in conflict_globs. |
|
1130 | if local_ns is not None: | |
|
1131 | conflict_globs = {} | |
|
1130 | conflict_globs = {} | |
|
1131 | if local_ns and cell is None: | |
|
1132 | 1132 | for var_name, var_val in glob.items(): |
|
1133 | 1133 | if var_name in local_ns: |
|
1134 | 1134 | conflict_globs[var_name] = var_val |
@@ -1154,9 +1154,8 b' python-profiler package from non-free.""")' | |||
|
1154 | 1154 | timeit_result = TimeitResult(number, repeat, best, worst, all_runs, tc, precision) |
|
1155 | 1155 | |
|
1156 | 1156 | # Restore global vars from conflict_globs |
|
1157 | if local_ns is not None: | |
|
1158 |
|
|
|
1159 | glob.update(conflict_globs) | |
|
1157 | if conflict_globs: | |
|
1158 | glob.update(conflict_globs) | |
|
1160 | 1159 | |
|
1161 | 1160 | if not quiet : |
|
1162 | 1161 | # Check best timing is greater than zero to avoid a |
@@ -419,6 +419,16 b' def test_time3():' | |||
|
419 | 419 | "run = 0\n" |
|
420 | 420 | "run += 1") |
|
421 | 421 | |
|
422 | def test_time_local_ns(): | |
|
423 | """ | |
|
424 | Test that local_ns is actually global_ns when running a cell magic | |
|
425 | """ | |
|
426 | ip = get_ipython() | |
|
427 | ip.run_cell("%%time\n" | |
|
428 | "myvar = 1") | |
|
429 | nt.assert_equal(ip.user_ns['myvar'], 1) | |
|
430 | del ip.user_ns['myvar'] | |
|
431 | ||
|
422 | 432 | def test_doctest_mode(): |
|
423 | 433 | "Toggle doctest_mode twice, it should be a no-op and run without error" |
|
424 | 434 | _ip.magic('doctest_mode') |
General Comments 0
You need to be logged in to leave comments.
Login now