##// END OF EJS Templates
Simplify logic for deciding when to rewrite expressions for autocall.
Bradley Froehle -
Show More
@@ -827,29 +827,32 b' class AutoHandler(PrefilterHandler):'
827 827 newcmd = '%s(%s)' % (ifun,",".join(the_rest.split()))
828 828 else:
829 829 # Auto-paren.
830 # We only apply it to argument-less calls if the autocall
831 # parameter is set to 2. We only need to check that autocall is <
832 # 2, since this function isn't called unless it's at least 1.
833 if (not the_rest and (self.shell.autocall < 2) and not force_auto) \
834 or the_rest.startswith("("):
835 newcmd = '%s %s' % (ifun,the_rest)
836 auto_rewrite = False
830 if force_auto:
831 # Don't rewrite if it is already a call.
832 do_rewrite = not the_rest.startswith('(')
837 833 else:
838 if not force_auto and the_rest.startswith('['):
839 if hasattr(obj,'__getitem__'):
834 if not the_rest:
835 # We only apply it to argument-less calls if the autocall
836 # parameter is set to 2.
837 do_rewrite = (self.shell.autocall >= 2)
838 elif the_rest.startswith('[') and hasattr(obj, '__getitem__'):
840 839 # Don't autocall in this case: item access for an object
841 840 # which is BOTH callable and implements __getitem__.
842 newcmd = '%s %s' % (ifun,the_rest)
843 auto_rewrite = False
841 do_rewrite = False
844 842 else:
845 # if the object doesn't support [] access, go ahead and
846 # autocall
847 newcmd = '%s(%s)' % (ifun.rstrip(),the_rest)
848 elif the_rest.endswith(';'):
843 do_rewrite = True
844
845 # Figure out the rewritten command
846 if do_rewrite:
847 if the_rest.endswith(';'):
849 848 newcmd = '%s(%s);' % (ifun.rstrip(),the_rest[:-1])
850 849 else:
851 850 newcmd = '%s(%s)' % (ifun.rstrip(), the_rest)
851 else:
852 normal_handler = self.prefilter_manager.get_handler_by_name('normal')
853 return normal_handler.handle(line_info)
852 854
855 # Display the rewritten call
853 856 if auto_rewrite:
854 857 self.shell.auto_rewrite_input(newcmd)
855 858
1 NO CONTENT: modified file
General Comments 0
You need to be logged in to leave comments. Login now