##// END OF EJS Templates
Fix autocall misfiring on print for python 2.6 and newer. Closes Bug #414967...
Fernando Perez -
Show More
@@ -15,6 +15,7 b''
15
15
16 # Python standard modules
16 # Python standard modules
17 import __builtin__
17 import __builtin__
18 import __future__
18 import bdb
19 import bdb
19 import inspect
20 import inspect
20 import os
21 import os
@@ -192,9 +193,7 b' python-profiler package from non-free.""")'
192
193
193 Has special code to detect magic functions.
194 Has special code to detect magic functions.
194 """
195 """
195
196 oname = oname.strip()
196 oname = oname.strip()
197
198 alias_ns = None
197 alias_ns = None
199 if namespaces is None:
198 if namespaces is None:
200 # Namespaces to search in:
199 # Namespaces to search in:
@@ -208,8 +207,16 b' python-profiler package from non-free.""")'
208 alias_ns = self.shell.alias_table
207 alias_ns = self.shell.alias_table
209
208
210 # initialize results to 'null'
209 # initialize results to 'null'
211 found = 0; obj = None; ospace = None; ds = None;
210 found = False; obj = None; ospace = None; ds = None;
212 ismagic = 0; isalias = 0; parent = None
211 ismagic = False; isalias = False; parent = None
212
213 # We need to special-case 'print', which as of python2.6 registers as a
214 # function but should only be treated as one if print_function was
215 # loaded with a future import. In this case, just bail.
216 if (oname == 'print' and not (self.shell.compile.compiler.flags &
217 __future__.CO_FUTURE_PRINT_FUNCTION)):
218 return {'found':found, 'obj':obj, 'namespace':ospace,
219 'ismagic':ismagic, 'isalias':isalias, 'parent':parent}
213
220
214 # Look for the given name by splitting it in parts. If the head is
221 # Look for the given name by splitting it in parts. If the head is
215 # found, then we look for all the remaining parts as members, and only
222 # found, then we look for all the remaining parts as members, and only
@@ -234,10 +241,10 b' python-profiler package from non-free.""")'
234 break
241 break
235 else:
242 else:
236 # If we finish the for loop (no break), we got all members
243 # If we finish the for loop (no break), we got all members
237 found = 1
244 found = True
238 ospace = nsname
245 ospace = nsname
239 if ns == alias_ns:
246 if ns == alias_ns:
240 isalias = 1
247 isalias = True
241 break # namespace loop
248 break # namespace loop
242
249
243 # Try to see if it's magic
250 # Try to see if it's magic
@@ -246,14 +253,14 b' python-profiler package from non-free.""")'
246 oname = oname[1:]
253 oname = oname[1:]
247 obj = getattr(self,'magic_'+oname,None)
254 obj = getattr(self,'magic_'+oname,None)
248 if obj is not None:
255 if obj is not None:
249 found = 1
256 found = True
250 ospace = 'IPython internal'
257 ospace = 'IPython internal'
251 ismagic = 1
258 ismagic = True
252
259
253 # Last try: special-case some literals like '', [], {}, etc:
260 # Last try: special-case some literals like '', [], {}, etc:
254 if not found and oname_head in ["''",'""','[]','{}','()']:
261 if not found and oname_head in ["''",'""','[]','{}','()']:
255 obj = eval(oname_head)
262 obj = eval(oname_head)
256 found = 1
263 found = True
257 ospace = 'Interactive'
264 ospace = 'Interactive'
258
265
259 return {'found':found, 'obj':obj, 'namespace':ospace,
266 return {'found':found, 'obj':obj, 'namespace':ospace,
General Comments 0
You need to be logged in to leave comments. Login now