From b7d03ed6b16013973b82c4725c79c30ac0a84903 2016-06-22 16:45:19 From: Matthias Bussonnier Date: 2016-06-22 16:45:19 Subject: [PATCH] Remove the "autoedit_syntax" feature. IPython used to (a long time ago, in a galaxy far far away) have the ability to automatically open an editor in case a wild syntax error appears. The configuration option to enable that was not working for a few years, and apparently we by mistake re enabled it, to discover that the feature is actually broken. So this plainly remove the code to support this feature, at the exception of the `fix_error_editor` hook. Indeed it is public API, so for now as it seem to be used only for this feature, we'll just raise a UserWarning (there is roughly 0 chance of this being tested as it's used mostly interactively, so DeprecationWarnings would be unseen). We'll remove later if no complaints Closes #9603 --- diff --git a/IPython/core/hooks.py b/IPython/core/hooks.py index 79503de..b0d0e6c 100644 --- a/IPython/core/hooks.py +++ b/IPython/core/hooks.py @@ -37,6 +37,7 @@ example, you could use a startup file like this:: import os import subprocess +import warnings import sys from IPython.core.error import TryNext @@ -83,13 +84,24 @@ def editor(self, filename, linenum=None, wait=True): import tempfile def fix_error_editor(self,filename,linenum,column,msg): - """Open the editor at the given filename, linenumber, column and + """DEPRECATED + + Open the editor at the given filename, linenumber, column and show an error message. This is used for correcting syntax errors. The current implementation only has special support for the VIM editor, and falls back on the 'editor' hook if VIM is not used. - Call ip.set_hook('fix_error_editor',youfunc) to use your own function, + Call ip.set_hook('fix_error_editor',yourfunc) to use your own function, """ + + warnings.warn(""" +`fix_error_editor` is pending deprecation as of IPython 5.0 and will be removed +in future versions. It appears to be used only for automatically fixing syntax +error that has been broken for a few years and has thus been removed. If you +happend to use this function and still need it please make your voice heard on +the mailing list ipython-dev@scipy.org , or on the GitHub Issue tracker: +https://github.com/ipython/ipython/issues/9649 """, UserWarning) + def vim_quickfix_file(): t = tempfile.NamedTemporaryFile() t.write('%s:%d:%d:%s\n' % (filename,linenum,column,msg)) diff --git a/IPython/terminal/interactiveshell.py b/IPython/terminal/interactiveshell.py index b4b3f17..233cb1f 100644 --- a/IPython/terminal/interactiveshell.py +++ b/IPython/terminal/interactiveshell.py @@ -93,11 +93,6 @@ class TerminalInteractiveShell(InteractiveShell): def debugger_cls(self): return Pdb if self.simple_prompt else TerminalPdb - autoedit_syntax = Bool(False, - help="auto editing of files with syntax errors.", - ).tag(config=True) - - confirm_exit = Bool(True, help=""" Set to confirm when you try to exit IPython with an EOF (Control-D @@ -476,8 +471,6 @@ class TerminalInteractiveShell(InteractiveShell): else: if code: self.run_cell(code, store_history=True) - if self.autoedit_syntax and self.SyntaxTB.last_syntax_error: - self.edit_syntax_error() def mainloop(self, display_banner=DISPLAY_BANNER_DEPRECATED): # An extra layer of protection in case someone mashing Ctrl-C breaks @@ -505,65 +498,6 @@ class TerminalInteractiveShell(InteractiveShell): else: self._inputhook = None - # Methods to support auto-editing of SyntaxErrors: - - def edit_syntax_error(self): - """The bottom half of the syntax error handler called in the main loop. - - Loop until syntax error is fixed or user cancels. - """ - - while self.SyntaxTB.last_syntax_error: - # copy and clear last_syntax_error - err = self.SyntaxTB.clear_err_state() - if not self._should_recompile(err): - return - try: - # may set last_syntax_error again if a SyntaxError is raised - self.safe_execfile(err.filename, self.user_ns) - except: - self.showtraceback() - else: - try: - with open(err.filename) as f: - # This should be inside a display_trap block and I - # think it is. - sys.displayhook(f.read()) - except: - self.showtraceback() - - def _should_recompile(self, e): - """Utility routine for edit_syntax_error""" - - if e.filename in ('', '', '', - '', '', - None): - return False - try: - if (self.autoedit_syntax and - not self.ask_yes_no( - 'Return to editor to correct syntax error? ' - '[Y/n] ', 'y')): - return False - except EOFError: - return False - - def int0(x): - try: - return int(x) - except TypeError: - return 0 - - # always pass integer line and offset values to editor hook - try: - self.hooks.fix_error_editor(e.filename, - int0(e.lineno), int0(e.offset), - e.msg) - except TryNext: - warn('Could not open editor') - return False - return True - # Run !system commands directly, not through pipes, so terminal programs # work correctly. system = InteractiveShell.system_raw diff --git a/docs/source/whatsnew/version5.rst b/docs/source/whatsnew/version5.rst index 5680ee5..9052e9c 100644 --- a/docs/source/whatsnew/version5.rst +++ b/docs/source/whatsnew/version5.rst @@ -64,8 +64,6 @@ Most of the above remarks also affect `IPython.core.debugger.Pdb`, the `%debug` and `%pdb` magic which do not use readline anymore either. - - Provisional Changes ------------------- @@ -109,6 +107,34 @@ widgets... As stated above this is nightly experimental feature with a lot of it. +Removed Feature +--------------- + + - ``TerminalInteractiveShell.autoedit_syntax`` Has been broken for many years now +apparently. It has been removed. + + +Deprecated Features +------------------- + +Some deprecated feature, don't forget to enable `DeprecationWarning` as error +of you are using IPython in Continuous Integration setup or in your testing in general: + +.. code:: + :python: + + import warnings + warnings.filterwarnings('error', '.*', DeprecationWarning, module='yourmodule.*') + + + - `hooks.fix_error_editor` seem to be unused and is pending deprecation. + - `IPython/core/excolors.py:ExceptionColors` is deprecated. + - `IPython.core.InteractiveShell:write()` is deprecated, use `sys.stdout` instead. + - `IPython.core.InteractiveShell:write_err()` is deprecated, use `sys.stderr` instead. + - The `formatter` keyword argument to `Inspector.info` in `IPython.core.oinspec` has now no effects. + - The `global_ns` keyword argument of IPython Embed was deprecated, and will now have no effect. Use `module` keyword argument instead. + + Known Issues: -------------