##// END OF EJS Templates
Merge pull request #4237 from takluyver/keywords-shadow...
Thomas Kluyver -
r12884:ee0f717b merge
parent child Browse files
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,30 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 ip.autocall = 0
32
33 try:
34 # These should not be transformed - they are shadowed by other names
35 for name in ['if', 'zip', 'get_ipython']: # keyword, builtin, global
36 ip.register_magic_function(dummy_magic, magic_name=name)
37 res = ip.prefilter(name+' foo')
38 nt.assert_equal(res, name+' foo')
39 del ip.magics_manager.magics['line'][name]
40
41 # These should be transformed
42 for name in ['fi', 'piz', 'nohtypi_teg']:
43 ip.register_magic_function(dummy_magic, magic_name=name)
44 res = ip.prefilter(name+' foo')
45 nt.assert_not_equal(res, name+' foo')
46 del ip.magics_manager.magics['line'][name]
47
48 finally:
49 ip.automagic = prev_automagic_state
26 50
27 51 def test_autocall_binops():
28 52 """See https://github.com/ipython/ipython/issues/81"""
General Comments 0
You need to be logged in to leave comments. Login now