Skip to content

Commit

Permalink
Ruffisation (ipython#14625)
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau authored Dec 20, 2024
2 parents 0334d9f + ea1b8f4 commit 5d58068
Show file tree
Hide file tree
Showing 41 changed files with 457 additions and 450 deletions.
4 changes: 2 additions & 2 deletions IPython/core/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ def __init__(self, **kwargs):
# ensure current working directory exists
try:
os.getcwd()
except:
except Exception:
# exit if cwd doesn't exist
self.log.error("Current working directory doesn't exist.")
self.exit(1)
Expand Down Expand Up @@ -342,7 +342,7 @@ def load_config_file(self, suppress_errors=IPYTHON_SUPPRESS_CONFIG_ERRORS):
try:
if suppress_errors is not None:
old_value = Application.raise_config_file_errors
Application.raise_config_file_errors = not suppress_errors;
Application.raise_config_file_errors = not suppress_errors
Application.load_config_file(
self,
base_config,
Expand Down
7 changes: 5 additions & 2 deletions IPython/core/builtin_trap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@
from traitlets import Instance


class __BuiltinUndefined(object): pass
class __BuiltinUndefined:
pass
BuiltinUndefined = __BuiltinUndefined()

class __HideBuiltin(object): pass

class __HideBuiltin:
pass
HideBuiltin = __HideBuiltin()


Expand Down
1 change: 0 additions & 1 deletion IPython/core/compilerop.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import hashlib
import linecache
import operator
import time
from contextlib import contextmanager

#-----------------------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion IPython/core/completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
from IPython.utils import generics
from IPython.utils.decorators import sphinx_options
from IPython.utils.dir2 import dir2, get_real_method
from IPython.utils.docs import GENERATING_DOCUMENTATION
from IPython.utils.path import ensure_dir_exists
from IPython.utils.process import arg_split
from traitlets import (
Expand Down
7 changes: 1 addition & 6 deletions IPython/core/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@

from IPython import get_ipython
from IPython.core.excolors import exception_colors
from IPython.utils import PyColorize, coloransi, py3compat
from IPython.utils import PyColorize, py3compat

from typing import TYPE_CHECKING

Expand Down Expand Up @@ -281,11 +281,6 @@ def __init__(self, completekey=None, stdin=None, stdout=None, context=5, **kwarg
# module and add a few attributes needed for debugging
self.color_scheme_table = exception_colors()

# shorthands
C = coloransi.TermColors
cst = self.color_scheme_table


# Add a python parser so we can syntax highlight source while
# debugging.
self.parser = PyColorize.Parser(style=color_scheme)
Expand Down
2 changes: 1 addition & 1 deletion IPython/core/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def update_user_ns(self, result):
# by the user.
update_unders = True
for unders in ['_'*i for i in range(1,4)]:
if not unders in self.shell.user_ns:
if unders not in self.shell.user_ns:
continue
if getattr(self, unders) is not self.shell.user_ns.get(unders):
update_unders = False
Expand Down
3 changes: 0 additions & 3 deletions IPython/core/displaypub.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@
from traitlets.config.configurable import Configurable
from traitlets import List

# This used to be defined here - it is imported for backwards compatibility
from .display_functions import publish_display_data

import typing as t

# -----------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions IPython/core/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
# Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.

import os
import os.path
import sys
from importlib import import_module, reload

from traitlets.config.configurable import Configurable
from IPython.utils.path import ensure_dir_exists
from traitlets import Instance


Expand Down
1 change: 0 additions & 1 deletion IPython/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,6 @@ def store_output(self, line_num: int) -> None:
"""
if (not self.db_log_output) or (line_num not in self.output_hist_reprs):
return
lnum: int = line_num
output = self.output_hist_reprs[line_num]

with self.db_output_cache_lock:
Expand Down
67 changes: 33 additions & 34 deletions IPython/core/interactiveshell.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
from logging import error
from pathlib import Path
from typing import Callable
from typing import List as ListType, Dict as DictType, Any as AnyType
from typing import List as ListType, Any as AnyType
from typing import Optional, Sequence, Tuple
from warnings import warn

Expand Down Expand Up @@ -118,7 +118,7 @@ def __delitem__(self, key):
from IPython.display import display
from IPython.paths import get_ipython_dir
from IPython.testing.skipdoctest import skip_doctest
from IPython.utils import PyColorize, io, openpy, py3compat
from IPython.utils import PyColorize, openpy, py3compat
from IPython.utils.decorators import undoc
from IPython.utils.io import ask_yes_no
from IPython.utils.ipstruct import Struct
Expand All @@ -129,6 +129,18 @@ def __delitem__(self, key):
from IPython.utils.text import DollarFormatter, LSString, SList, format_screen
from IPython.core.oinspect import OInfo

from ast import Module

# we still need to run things using the asyncio eventloop, but there is no
# async integration

from .async_helpers import (
_asyncio_runner,
_curio_runner,
_pseudo_sync_runner,
_should_be_async,
_trio_runner,
)

sphinxify: Optional[Callable]

Expand Down Expand Up @@ -156,25 +168,10 @@ class ProvisionalWarning(DeprecationWarning):
"""
pass

from ast import Module

_assign_nodes = (ast.AugAssign, ast.AnnAssign, ast.Assign)
_single_targets_nodes = (ast.AugAssign, ast.AnnAssign)

#-----------------------------------------------------------------------------
# Await Helpers
#-----------------------------------------------------------------------------

# we still need to run things using the asyncio eventloop, but there is no
# async integration
from .async_helpers import (
_asyncio_runner,
_curio_runner,
_pseudo_sync_runner,
_should_be_async,
_trio_runner,
)

#-----------------------------------------------------------------------------
# Globals
#-----------------------------------------------------------------------------
Expand Down Expand Up @@ -220,7 +217,8 @@ def no_op(*a, **kw):
pass


class SpaceInInput(Exception): pass
class SpaceInInput(Exception):
pass


class SeparateUnicode(Unicode):
Expand All @@ -230,8 +228,9 @@ class SeparateUnicode(Unicode):
"""

def validate(self, obj, value):
if value == '0': value = ''
value = value.replace('\\n','\n')
if value == "0":
value = ""
value = value.replace("\\n", "\n")
return super(SeparateUnicode, self).validate(obj, value)


Expand Down Expand Up @@ -1572,7 +1571,7 @@ def push(self, variables, interactive=True):
for name in vlist:
try:
vdict[name] = eval(name, cf.f_globals, cf.f_locals)
except:
except Exception:
print('Could not get variable %s from %s' %
(name,cf.f_code.co_name))
else:
Expand Down Expand Up @@ -1731,7 +1730,7 @@ def _ofind(
obj = obj[int(part)]
else:
obj = getattr(obj, part)
except:
except Exception:
# Blanket except b/c some badly implemented objects
# allow __getattr__ to raise exceptions other than
# AttributeError, which then crashes IPython.
Expand Down Expand Up @@ -2022,7 +2021,7 @@ def wrapped(self,etype,value,tb,tb_offset=None):
try:
stb = handler(self,etype,value,tb,tb_offset=tb_offset)
return validate_stb(stb)
except:
except Exception:
# clear custom handler immediately
self.set_custom_exc((), None)
print("Custom TB Handler failed, unregistering", file=sys.stderr)
Expand Down Expand Up @@ -2215,7 +2214,7 @@ def showsyntaxerror(self, filename=None, running_compiled_code=False):
if filename and issubclass(etype, SyntaxError):
try:
value.filename = filename
except:
except Exception:
# Not the format we expect; leave it alone
pass

Expand Down Expand Up @@ -2861,7 +2860,7 @@ def user_expressions(self, expressions):
for key, expr in expressions.items():
try:
value = self._format_user_obj(eval(expr, global_ns, user_ns))
except:
except Exception:
value = self._user_obj_error()
out[key] = value
return out
Expand Down Expand Up @@ -2915,7 +2914,7 @@ def safe_execfile(self, fname, *where, exit_ignore=False, raise_exceptions=False
try:
with fname.open("rb"):
pass
except:
except Exception:
warn('Could not open file <%s> for safe execution.' % fname)
return

Expand Down Expand Up @@ -2945,7 +2944,7 @@ def safe_execfile(self, fname, *where, exit_ignore=False, raise_exceptions=False
raise
if not exit_ignore:
self.showtraceback(exception_only=True)
except:
except Exception:
if raise_exceptions:
raise
# tb offset is 2 because we wrap execfile
Expand Down Expand Up @@ -2973,7 +2972,7 @@ def safe_execfile_ipy(self, fname, shell_futures=False, raise_exceptions=False):
try:
with fname.open("rb"):
pass
except:
except Exception:
warn('Could not open file <%s> for safe execution.' % fname)
return

Expand Down Expand Up @@ -3003,7 +3002,7 @@ def get_cells():
result.raise_error()
elif not result.success:
break
except:
except Exception:
if raise_exceptions:
raise
self.showtraceback()
Expand Down Expand Up @@ -3033,7 +3032,7 @@ def safe_run_module(self, mod_name, where):
except SystemExit as status:
if status.code:
raise
except:
except Exception:
self.showtraceback()
warn('Unknown failure executing module: <%s>' % mod_name)

Expand Down Expand Up @@ -3519,7 +3518,7 @@ def compare(code):
if softspace(sys.stdout, 0):
print()

except:
except Exception:
# It's possible to have exceptions raised here, typically by
# compilation of odd code (such as a naked 'return' outside a
# function) that did parse but isn't valid. Typically the exception
Expand Down Expand Up @@ -3591,7 +3590,7 @@ async def run_code(self, code_obj, result=None, *, async_=False):
if result is not None:
result.error_in_exec = value
self.CustomTB(etype, value, tb)
except:
except Exception:
if result is not None:
result.error_in_exec = sys.exc_info()[1]
self.showtraceback(running_compiled_code=True)
Expand Down Expand Up @@ -3657,12 +3656,12 @@ def enable_matplotlib(self, gui=None):
if not _matplotlib_manages_backends() and gui in (None, "auto"):
# Early import of backend_inline required for its side effect of
# calling _enable_matplotlib_integration()
import matplotlib_inline.backend_inline
import matplotlib_inline.backend_inline # noqa : F401

from IPython.core import pylabtools as pt
gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)

if gui != None:
if gui is not None:
# If we have our first gui selection, store it
if self.pylab_gui_select is None:
self.pylab_gui_select = gui
Expand Down
49 changes: 26 additions & 23 deletions IPython/core/magics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
"""Implementation of all the magic functions built into IPython.
"""
#-----------------------------------------------------------------------------

# -----------------------------------------------------------------------------
# Copyright (c) 2012 The IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------

from ..magic import Magics, magics_class
from .auto import AutoMagics
from .basic import BasicMagics, AsyncMagics
from .code import CodeMagics, MacroToEdit
from .config import ConfigMagics
from .display import DisplayMagics
from .execution import ExecutionMagics
from .extension import ExtensionMagics
from .history import HistoryMagics
from .logging import LoggingMagics
from .namespace import NamespaceMagics
from .osm import OSMagics
from .packaging import PackagingMagics
from .pylab import PylabMagics
from .script import ScriptMagics

#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------

from ..magic import Magics as Magics, magics_class as magics_class
from .auto import AutoMagics as AutoMagics
from .basic import BasicMagics as BasicMagics, AsyncMagics as AsyncMagics
from .code import CodeMagics as CodeMagics, MacroToEdit as MacroToEdit
from .config import ConfigMagics as ConfigMagics
from .display import DisplayMagics as DisplayMagics
from .execution import ExecutionMagics as ExecutionMagics
from .extension import ExtensionMagics as ExtensionMagics
from .history import HistoryMagics as HistoryMagics
from .logging import LoggingMagics as LoggingMagics
from .namespace import NamespaceMagics as NamespaceMagics
from .osm import OSMagics as OSMagics
from .packaging import PackagingMagics as PackagingMagics
from .pylab import PylabMagics as PylabMagics
from .script import ScriptMagics as ScriptMagics


# -----------------------------------------------------------------------------
# Magic implementation classes
#-----------------------------------------------------------------------------
# -----------------------------------------------------------------------------


@magics_class
class UserMagics(Magics):
Expand Down
4 changes: 2 additions & 2 deletions IPython/core/magics/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ def errorMessage() -> str:
return error

if parameter_s:
if not parameter_s in map(str, valid_modes.keys()):
if parameter_s not in map(str, valid_modes.keys()):
error(errorMessage())
return
arg = int(parameter_s)
else:
arg = 'toggle'

if not arg in (*list(valid_modes.keys()), "toggle"):
if arg not in (*list(valid_modes.keys()), "toggle"):
error(errorMessage())
return

Expand Down
Loading

0 comments on commit 5d58068

Please sign in to comment.