Show More
@@ -24,6 +24,7 b' Authors:' | |||
|
24 | 24 | # Imports |
|
25 | 25 | #----------------------------------------------------------------------------- |
|
26 | 26 | |
|
27 | from keyword import iskeyword | |
|
27 | 28 | import re |
|
28 | 29 | |
|
29 | 30 | from IPython.core.autocall import IPyAutocall |
@@ -80,7 +81,8 b' def is_shadowed(identifier, ip):' | |||
|
80 | 81 | # This is much safer than calling ofind, which can change state |
|
81 | 82 | return (identifier in ip.user_ns \ |
|
82 | 83 | or identifier in ip.user_global_ns \ |
|
83 |
or identifier in ip.ns_table['builtin'] |
|
|
84 | or identifier in ip.ns_table['builtin']\ | |
|
85 | or iskeyword(identifier)) | |
|
84 | 86 | |
|
85 | 87 | |
|
86 | 88 | #----------------------------------------------------------------------------- |
@@ -23,6 +23,29 b' def test_prefilter():' | |||
|
23 | 23 | for raw, correct in pairs: |
|
24 | 24 | nt.assert_equal(ip.prefilter(raw), correct) |
|
25 | 25 | |
|
26 | def test_prefilter_shadowed(): | |
|
27 | def dummy_magic(line): pass | |
|
28 | ||
|
29 | prev_automagic_state = ip.automagic | |
|
30 | ip.automagic = True | |
|
31 | ||
|
32 | try: | |
|
33 | # These should not be transformed - they are shadowed by other names | |
|
34 | for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global | |
|
35 | ip.register_magic_function(dummy_magic, magic_name=name) | |
|
36 | res = ip.prefilter(name+' foo') | |
|
37 | nt.assert_equal(res, name+' foo') | |
|
38 | del ip.magics_manager.magics['line'][name] | |
|
39 | ||
|
40 | # These should be transformed | |
|
41 | for name in ['fi', 'piz', 'nohtypi_teg']: | |
|
42 | ip.register_magic_function(dummy_magic, magic_name=name) | |
|
43 | res = ip.prefilter(name+' foo') | |
|
44 | nt.assert_not_equal(res, name+' foo') | |
|
45 | del ip.magics_manager.magics['line'][name] | |
|
46 | ||
|
47 | finally: | |
|
48 | ip.automagic = prev_automagic_state | |
|
26 | 49 | |
|
27 | 50 | def test_autocall_binops(): |
|
28 | 51 | """See https://github.com/ipython/ipython/issues/81""" |
General Comments 0
You need to be logged in to leave comments.
Login now