Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean python 2 artifacts. Fix #826 #827

Merged
merged 3 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/embedding/internal_ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def mpl_kernel(gui):
return kernel


class InternalIPKernel(object):
class InternalIPKernel:

def init_ipkernel(self, backend):
# Start IPython kernel with GUI event loop and mpl support
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/comm/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def _default_topic(self):
def __init__(self, target_name='', data=None, metadata=None, buffers=None, **kwargs):
if target_name:
kwargs['target_name'] = target_name
super(Comm, self).__init__(**kwargs)
super().__init__(**kwargs)
if self.kernel:
if self.primary:
# I am primary, open my peer.
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def get_file_name(code):
class XCachingCompiler(CachingCompiler):

def __init__(self, *args, **kwargs):
super(XCachingCompiler, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self.log = None

def get_code_name(self, raw_code, code, number):
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/debugger.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ async def richInspectVariables(self, message):
else:
# The code has stopped on a breakpoint, we use the setExpression
# request to get the rich representation of the variable
code = "get_ipython().display_formatter.format(" + var_name + ")"
code = f"get_ipython().display_formatter.format({var_name})"
frame_id = message["arguments"]["frameId"]
seq = message["seq"]
reply = await self._forward_message(
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from jupyter_client.session import extract_header, Session


class ZMQDisplayHook(object):
class ZMQDisplayHook:
"""A simple displayhook that publishes the object's repr over a ZeroMQ
socket."""
topic = b'execute_result'
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/eventloops.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def loop_tk(kernel):
# file handlers are not available on Windows
if hasattr(app, 'createfilehandler'):
# A basic wrapper for structural similarity with the Windows version
class BasicAppWrapper(object):
class BasicAppWrapper:
def __init__(self, app):
self.app = app
self.app.withdraw()
Expand Down Expand Up @@ -257,7 +257,7 @@ def process_stream_events(stream, *a, **kw):
# Tk uses milliseconds
poll_interval = int(1000 * kernel._poll_interval)

class TimedAppWrapper(object):
class TimedAppWrapper:
def __init__(self, app, func):
self.app = app
self.app.withdraw()
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/gui/gtk3embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Classes and functions
#-----------------------------------------------------------------------------

class GTKEmbed(object):
class GTKEmbed:
"""A class to embed a kernel into the GTK main event loop.
"""
def __init__(self, kernel):
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/gui/gtkembed.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# Classes and functions
#-----------------------------------------------------------------------------

class GTKEmbed(object):
class GTKEmbed:
"""A class to embed a kernel into the GTK main event loop.
"""
def __init__(self, kernel):
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/inprocess/blocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
class BlockingInProcessChannel(InProcessChannel):

def __init__(self, *args, **kwds):
super(BlockingInProcessChannel, self).__init__(*args, **kwds)
super().__init__(*args, **kwds)
self._in_queue = Queue()

def call_handlers(self, msg):
Expand Down
8 changes: 4 additions & 4 deletions ipykernel/inprocess/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
# Channel classes
#-----------------------------------------------------------------------------

class InProcessChannel(object):
class InProcessChannel:
"""Base class for in-process channels."""
proxy_methods = []

def __init__(self, client=None):
super(InProcessChannel, self).__init__()
super().__init__()
self.client = client
self._is_alive = False

Expand Down Expand Up @@ -57,7 +57,7 @@ def process_events(self):



class InProcessHBChannel(object):
class InProcessHBChannel:
"""A dummy heartbeat channel interface for in-process kernels.

Normally we use the heartbeat to check that the kernel process is alive.
Expand All @@ -68,7 +68,7 @@ class InProcessHBChannel(object):
time_to_dead = 3.0

def __init__(self, client=None):
super(InProcessHBChannel, self).__init__()
super().__init__()
self.client = client
self._is_alive = False
self._pause = True
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/inprocess/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ def _default_blocking_class(self):
return BlockingInProcessKernelClient

def get_connection_info(self):
d = super(InProcessKernelClient, self).get_connection_info()
d = super().get_connection_info()
d['kernel'] = self.kernel
return d

def start_channels(self, *args, **kwargs):
super(InProcessKernelClient, self).start_channels()
super().start_channels()
self.kernel.frontends.append(self)

@property
Expand Down
10 changes: 5 additions & 5 deletions ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ def _default_iopub_socket(self):
stdin_socket = Instance(DummySocket, ())

def __init__(self, **traits):
super(InProcessKernel, self).__init__(**traits)
super().__init__(**traits)

self._underlying_iopub_socket.observe(self._io_dispatch, names=['message_sent'])
self.shell.kernel = self

async def execute_request(self, stream, ident, parent):
""" Override for temporary IO redirection. """
with self._redirected_io():
await super(InProcessKernel, self).execute_request(stream, ident, parent)
await super().execute_request(stream, ident, parent)

def start(self):
""" Override registration of dispatchers for streams. """
Expand Down Expand Up @@ -106,7 +106,7 @@ def _input_request(self, prompt, ident, parent, password=False):
break
else:
logging.error('No frontend found for raw_input request')
return str()
return ''

# Await a response.
while self.raw_input_str is None:
Expand Down Expand Up @@ -183,13 +183,13 @@ def enable_matplotlib(self, gui=None):
"""Enable matplotlib integration for the kernel."""
if not gui:
gui = self.kernel.gui
return super(InProcessInteractiveShell, self).enable_matplotlib(gui)
return super().enable_matplotlib(gui)

def enable_pylab(self, gui=None, import_all=True, welcome_message=False):
"""Activate pylab support at runtime."""
if not gui:
gui = self.kernel.gui
return super(InProcessInteractiveShell, self).enable_pylab(gui, import_all,
return super().enable_pylab(gui, import_all,
welcome_message)

InteractiveShellABC.register(InProcessInteractiveShell)
2 changes: 1 addition & 1 deletion ipykernel/inprocess/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def is_alive(self):

def client(self, **kwargs):
kwargs['kernel'] = self.kernel
return super(InProcessKernelManager, self).client(**kwargs)
return super().client(**kwargs)


#-----------------------------------------------------------------------------
Expand Down
26 changes: 13 additions & 13 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
#-----------------------------------------------------------------------------


class IOPubThread(object):
class IOPubThread:
"""An object for sending IOPub messages in a background thread

Prevents a blocking main thread from delaying output from threads.
Expand Down Expand Up @@ -239,7 +239,7 @@ def _really_send(self, msg, *args, **kwargs):
ctx.term()


class BackgroundSocket(object):
class BackgroundSocket:
"""Wrapper around IOPub thread that provides zmq send[_multipart]"""
io_thread = None

Expand All @@ -250,26 +250,26 @@ def __getattr__(self, attr):
"""Wrap socket attr access for backward-compatibility"""
if attr.startswith('__') and attr.endswith('__'):
# don't wrap magic methods
super(BackgroundSocket, self).__getattr__(attr)
super().__getattr__(attr)
if hasattr(self.io_thread.socket, attr):
warnings.warn(
"Accessing zmq Socket attribute {attr} on BackgroundSocket"
" is deprecated since ipykernel 4.3.0"
" use .io_thread.socket.{attr}".format(attr=attr),
f"Accessing zmq Socket attribute {attr} on BackgroundSocket"
f" is deprecated since ipykernel 4.3.0"
f" use .io_thread.socket.{attr}",
DeprecationWarning,
stacklevel=2,
)
return getattr(self.io_thread.socket, attr)
super(BackgroundSocket, self).__getattr__(attr)
super().__getattr__(attr)

def __setattr__(self, attr, value):
if attr == 'io_thread' or (attr.startswith('__' and attr.endswith('__'))):
super(BackgroundSocket, self).__setattr__(attr, value)
super().__setattr__(attr, value)
else:
warnings.warn(
"Setting zmq Socket attribute {attr} on BackgroundSocket"
" is deprecated since ipykernel 4.3.0"
" use .io_thread.socket.{attr}".format(attr=attr),
f"Setting zmq Socket attribute {attr} on BackgroundSocket"
f" is deprecated since ipykernel 4.3.0"
f" use .io_thread.socket.{attr}",
DeprecationWarning,
stacklevel=2,
)
Expand Down Expand Up @@ -484,7 +484,7 @@ def _flush(self):
self.echo.flush()
except OSError as e:
if self.echo is not sys.__stderr__:
print("Flush failed: {}".format(e),
print(f"Flush failed: {e}",
file=sys.__stderr__)

data = self._flush_buffer()
Expand Down Expand Up @@ -517,7 +517,7 @@ def write(self, string: str) -> int:
self.echo.write(string)
except OSError as e:
if self.echo is not sys.__stderr__:
print("Write failed: {}".format(e),
print(f"Write failed: {e}",
file=sys.__stderr__)

if self.pub_thread is None:
Expand Down
10 changes: 5 additions & 5 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def _user_ns_changed(self, change):
_sys_eval_input = Any()

def __init__(self, **kwargs):
super(IPythonKernel, self).__init__(**kwargs)
super().__init__(**kwargs)

# Initialize the Debugger
if _is_debugpy_available:
Expand Down Expand Up @@ -175,13 +175,13 @@ def start(self):
self.log.warning("debugpy_stream undefined, debugging will not be enabled")
else:
self.debugpy_stream.on_recv(self.dispatch_debugpy, copy=False)
super(IPythonKernel, self).start()
super().start()

def set_parent(self, ident, parent, channel='shell'):
"""Overridden from parent to tell the display hook and output streams
about the parent message.
"""
super(IPythonKernel, self).set_parent(ident, parent, channel)
super().set_parent(ident, parent, channel)
if channel == 'shell':
self.shell.set_parent(parent)

Expand All @@ -190,7 +190,7 @@ def init_metadata(self, parent):

Run at the beginning of each execution request.
"""
md = super(IPythonKernel, self).init_metadata(parent)
md = super().init_metadata(parent)
# FIXME: remove deprecated ipyparallel-specific code
# This is required for ipyparallel < 5.0
md.update({
Expand Down Expand Up @@ -591,4 +591,4 @@ def __init__(self, *args, **kwargs):
import warnings
warnings.warn('Kernel is a deprecated alias of ipykernel.ipkernel.IPythonKernel',
DeprecationWarning)
super(Kernel, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
6 changes: 3 additions & 3 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def cleanup_connection_file(self):
self.log.debug("Cleaning up connection file: %s", cf)
try:
os.remove(cf)
except (IOError, OSError):
except OSError:
pass

self.cleanup_ipc_files()
Expand All @@ -257,7 +257,7 @@ def init_connection_file(self):
self.connection_file = "kernel-%s.json"%os.getpid()
try:
self.connection_file = filefind(self.connection_file, ['.', self.connection_dir])
except IOError:
except OSError:
self.log.debug("Connection file not found: %s", self.connection_file)
# This means I own it, and I'll create it in this directory:
os.makedirs(os.path.dirname(self.abs_connection_file), mode=0o700, exist_ok=True)
Expand Down Expand Up @@ -621,7 +621,7 @@ def init_pdb(self):
@catch_config_error
def initialize(self, argv=None):
self._init_asyncio_patch()
super(IPKernelApp, self).initialize(argv)
super().initialize(argv)
if self.subapp is not None:
return

Expand Down
2 changes: 1 addition & 1 deletion ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def _parent_header(self):
control_msg_types = msg_types + ['clear_request', 'abort_request', 'debug_request']

def __init__(self, **kwargs):
super(Kernel, self).__init__(**kwargs)
super().__init__(**kwargs)
# Build dict of handlers for message types
self.shell_handlers = {}
for msg_type in self.msg_types:
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/parentpoller.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ParentPollerUnix(Thread):
"""

def __init__(self):
super(ParentPollerUnix, self).__init__()
super().__init__()
self.daemon = True

def run(self):
Expand Down Expand Up @@ -60,7 +60,7 @@ def __init__(self, interrupt_handle=None, parent_handle=None):
handle is signaled.
"""
assert(interrupt_handle or parent_handle)
super(ParentPollerWindows, self).__init__()
super().__init__()
if ctypes is None:
raise ImportError("ParentPollerWindows requires ctypes")
self.daemon = True
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/pickleutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def use_cloudpickle():
#-------------------------------------------------------------------------------


class CannedObject(object):
class CannedObject:
def __init__(self, obj, keys=[], hook=None):
"""can an object for safe pickling

Expand Down
2 changes: 1 addition & 1 deletion ipykernel/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def teardown():

try:
shutil.rmtree(tmp)
except (OSError, IOError):
except OSError:
# no such file
pass
2 changes: 1 addition & 1 deletion ipykernel/tests/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_async_interrupt(asynclib, request):

flush_channels(KC)
msg_id = KC.execute(
"print('begin'); import {0}; await {0}.sleep(5)".format(asynclib)
f"print('begin'); import {asynclib}; await {asynclib}.sleep(5)"
)
busy = KC.get_iopub_msg(timeout=TIMEOUT)
validate_message(busy, "status", msg_id)
Expand Down
Loading