From e7fd431d8b1fd4fd032190d1d9bb1d373d97b574 2021-12-09 01:05:10 From: Matthias Bussonnier Date: 2021-12-09 01:05:10 Subject: [PATCH] Remove many deprecation and bump traitlets to 5+ Many old hooks from debugger removed, We now are traitlets 5+ --- diff --git a/IPython/core/application.py b/IPython/core/application.py index 85c9127..2b26d4f 100644 --- a/IPython/core/application.py +++ b/IPython/core/application.py @@ -256,16 +256,6 @@ class BaseIPythonApplication(Application): # Various stages of Application creation #------------------------------------------------------------------------- - deprecated_subcommands = {} - - def initialize_subcommand(self, subc, argv=None): - if subc in self.deprecated_subcommands: - self.log.warning("Subcommand `ipython {sub}` is deprecated and will be removed " - "in future versions.".format(sub=subc)) - self.log.warning("You likely want to use `jupyter {sub}` in the " - "future".format(sub=subc)) - return super(BaseIPythonApplication, self).initialize_subcommand(subc, argv) - def init_crash_handler(self): """Create a crash handler, typically setting sys.excepthook to it.""" self.crash_handler = self.crash_handler_class(self) diff --git a/IPython/core/debugger.py b/IPython/core/debugger.py index d9095d0..d3e4ec2 100644 --- a/IPython/core/debugger.py +++ b/IPython/core/debugger.py @@ -144,22 +144,15 @@ def BdbQuit_excepthook(et, ev, tb, excepthook=None): All other exceptions are processed using the `excepthook` parameter. """ - warnings.warn("`BdbQuit_excepthook` is deprecated since version 5.1", - DeprecationWarning, stacklevel=2) - if et == bdb.BdbQuit: - print('Exiting Debugger.') - elif excepthook is not None: - excepthook(et, ev, tb) - else: - # Backwards compatibility. Raise deprecation warning? - BdbQuit_excepthook.excepthook_ori(et, ev, tb) + raise ValueError( + "`BdbQuit_excepthook` is deprecated since version 5.1", + ) def BdbQuit_IPython_excepthook(self, et, ev, tb, tb_offset=None): - warnings.warn( + raise ValueError( "`BdbQuit_IPython_excepthook` is deprecated since version 5.1", DeprecationWarning, stacklevel=2) - print('Exiting Debugger.') RGX_EXTRA_INDENT = re.compile(r'(?<=\n)\s+') diff --git a/IPython/core/formatters.py b/IPython/core/formatters.py index 07efeca..b2430f0 100644 --- a/IPython/core/formatters.py +++ b/IPython/core/formatters.py @@ -834,13 +834,11 @@ class JSONFormatter(BaseFormatter): if isinstance(r, tuple): # unpack data, metadata tuple for type checking on first element r, md = r - - # handle deprecated JSON-as-string form from IPython < 3 - if isinstance(r, str): - warnings.warn("JSON expects JSONable list/dict containers, not JSON strings", - FormatterWarning) - r = json.loads(r) - + + assert not isinstance( + r, str + ), "JSON-as-string has been deprecated since IPython < 3" + if md is not None: # put the tuple back together r = (r, md) diff --git a/IPython/core/interactiveshell.py b/IPython/core/interactiveshell.py index 39e84dd..020e892 100644 --- a/IPython/core/interactiveshell.py +++ b/IPython/core/interactiveshell.py @@ -906,7 +906,11 @@ class InteractiveShell(SingletonConfigurable): if _warn_deprecated and (name in IPython.core.hooks.deprecated): alternative = IPython.core.hooks.deprecated[name] - warn("Hook {} is deprecated. Use {} instead.".format(name, alternative), stacklevel=2) + raise ValueError( + "Hook {} has been deprecated since IPython 5.0. Use {} instead.".format( + name, alternative + ) + ) if not dp: dp = IPython.core.hooks.CommandChainDispatcher() @@ -933,9 +937,10 @@ class InteractiveShell(SingletonConfigurable): Register a function for calling after code execution. """ - warn("ip.register_post_execute is deprecated, use " - "ip.events.register('post_run_cell', func) instead.", stacklevel=2) - self.events.register('post_run_cell', func) + raise ValueError( + "ip.register_post_execute is deprecated since IPython 1.0, use " + "ip.events.register('post_run_cell', func) instead." + ) def _clear_warning_registry(self): # clear the warning registry, so that different code blocks with diff --git a/IPython/core/shellapp.py b/IPython/core/shellapp.py index c442658..f737bcb 100644 --- a/IPython/core/shellapp.py +++ b/IPython/core/shellapp.py @@ -98,11 +98,6 @@ shell_aliases = dict( ) shell_aliases['cache-size'] = 'InteractiveShell.cache_size' -if traitlets.version_info < (5, 0): - # traitlets 4 doesn't handle lists on CLI - shell_aliases["ext"] = "InteractiveShellApp.extra_extension" - - #----------------------------------------------------------------------------- # Main classes and functions #----------------------------------------------------------------------------- @@ -126,17 +121,6 @@ class InteractiveShellApp(Configurable): help="A list of dotted module names of IPython extensions to load." ).tag(config=True) - extra_extension = Unicode( - "", - help=""" - DEPRECATED. Dotted module name of a single extra IPython extension to load. - - Only one extension can be added this way. - - Only used with traitlets < 5.0, plural extra_extensions list is used in traitlets 5. - """, - ).tag(config=True) - extra_extensions = List( DottedObjectName(), help=""" @@ -293,8 +277,6 @@ class InteractiveShellApp(Configurable): extensions = ( self.default_extensions + self.extensions + self.extra_extensions ) - if self.extra_extension: - extensions.append(self.extra_extension) for ext in extensions: try: self.log.info("Loading IPython extension: %s" % ext) diff --git a/IPython/core/tests/test_formatters.py b/IPython/core/tests/test_formatters.py index 6ea40eb..26d3583 100644 --- a/IPython/core/tests/test_formatters.py +++ b/IPython/core/tests/test_formatters.py @@ -430,18 +430,6 @@ def test_ipython_display_formatter(): f.ipython_display_formatter.enabled = save_enabled -def test_json_as_string_deprecated(): - class JSONString(object): - def _repr_json_(self): - return '{}' - - f = JSONFormatter() - with warnings.catch_warnings(record=True) as w: - d = f(JSONString()) - assert d == {} - assert len(w) == 1 - - def test_repr_mime(): class HasReprMime(object): def _repr_mimebundle_(self, include=None, exclude=None): diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py index b95266e..ed39b7d 100755 --- a/IPython/terminal/ipapp.py +++ b/IPython/terminal/ipapp.py @@ -262,22 +262,6 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): # internal, not-configurable something_to_run=Bool(False) - def parse_command_line(self, argv=None): - """override to allow old '-pylab' flag with deprecation warning""" - - argv = sys.argv[1:] if argv is None else argv - - if '-pylab' in argv: - # deprecated `-pylab` given, - # warn and transform into current syntax - argv = argv[:] # copy, don't clobber - idx = argv.index('-pylab') - warnings.warn("`-pylab` flag has been deprecated.\n" - " Use `--matplotlib ` and import pylab manually.") - argv[idx] = '--pylab' - - return super(TerminalIPythonApp, self).parse_command_line(argv) - @catch_config_error def initialize(self, argv=None): """Do actions after construct, but before starting the app.""" diff --git a/IPython/utils/path.py b/IPython/utils/path.py index 273c519..375ae38 100644 --- a/IPython/utils/path.py +++ b/IPython/utils/path.py @@ -67,20 +67,6 @@ def get_long_path_name(path): return _get_long_path_name(path) -def unquote_filename(name, win32=(sys.platform=='win32')): - """ On Windows, remove leading and trailing quotes from filenames. - - This function has been deprecated and should not be used any more: - unquoting is now taken care of by :func:`IPython.utils.process.arg_split`. - """ - warn("'unquote_filename' is deprecated since IPython 5.0 and should not " - "be used anymore", DeprecationWarning, stacklevel=2) - if win32: - if name.startswith(("'", '"')) and name.endswith(("'", '"')): - name = name[1:-1] - return name - - def compress_user(path): """Reverse of :func:`os.path.expanduser` """ @@ -89,7 +75,7 @@ def compress_user(path): path = "~" + path[len(home):] return path -def get_py_filename(name, force_win32=None): +def get_py_filename(name): """Return a valid python filename in the current directory. If the given name is not a file, it adds '.py' and searches again. @@ -97,10 +83,6 @@ def get_py_filename(name, force_win32=None): """ name = os.path.expanduser(name) - if force_win32 is not None: - warn("The 'force_win32' argument to 'get_py_filename' is deprecated " - "since IPython 5.0 and should not be used anymore", - DeprecationWarning, stacklevel=2) if not os.path.isfile(name) and not name.endswith('.py'): name += '.py' if os.path.isfile(name): @@ -253,36 +235,6 @@ def get_xdg_cache_dir(): return None -@undoc -def get_ipython_dir(): - warn("get_ipython_dir has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) - from IPython.paths import get_ipython_dir - return get_ipython_dir() - -@undoc -def get_ipython_cache_dir(): - warn("get_ipython_cache_dir has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) - from IPython.paths import get_ipython_cache_dir - return get_ipython_cache_dir() - -@undoc -def get_ipython_package_dir(): - warn("get_ipython_package_dir has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) - from IPython.paths import get_ipython_package_dir - return get_ipython_package_dir() - -@undoc -def get_ipython_module_path(module_str): - warn("get_ipython_module_path has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) - from IPython.paths import get_ipython_module_path - return get_ipython_module_path(module_str) - -@undoc -def locate_profile(profile='default'): - warn("locate_profile has moved to the IPython.paths module since IPython 4.0.", DeprecationWarning, stacklevel=2) - from IPython.paths import locate_profile - return locate_profile(profile=profile) - def expand_path(s): """Expand $VARS and ~names in a string, like a shell diff --git a/IPython/utils/timing.py b/IPython/utils/timing.py index 92f6883..32741ac 100644 --- a/IPython/utils/timing.py +++ b/IPython/utils/timing.py @@ -62,6 +62,7 @@ if resource is not None and hasattr(resource, "getrusage"): Similar to clock(), but return a tuple of user/system times.""" return resource.getrusage(resource.RUSAGE_SELF)[:2] + else: # There is no distinction of user/system time under windows, so we just use # time.perff_counter() for everything... diff --git a/setup.py b/setup.py index 4c52f47..3aa9be2 100644 --- a/setup.py +++ b/setup.py @@ -171,7 +171,6 @@ extras_require = dict( nbconvert=["nbconvert"], ) - everything = set(chain.from_iterable(extras_require.values())) extras_require['all'] = list(sorted(everything))