Skip to content

Commit 2052290

Browse files
committed
Some removal of ipython_genutils.py3compat.
As in some of the other Jupyter Repositories; this start to remove ipython_genutils because of packaging problem in linux distribution (getting rid of nose). This is a step toward that. Note that this changes is slightly stricter in some area where function would previously accept string/bytes and now only accept one; but as far as I can tell are generally only used with one of those since we are Python 3 only.
1 parent 508a7dc commit 2052290

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

ipykernel/connect.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from IPython.core.profiledir import ProfileDir
1212
from IPython.paths import get_ipython_dir
1313
from ipython_genutils.path import filefind
14-
from ipython_genutils.py3compat import str_to_bytes
1514

1615
import jupyter_client
1716
from jupyter_client import write_connection_file
@@ -131,7 +130,7 @@ def get_connection_info(connection_file=None, unpack=False, profile=None):
131130
if unpack:
132131
info = json.loads(info)
133132
# ensure key is bytes:
134-
info['key'] = str_to_bytes(info.get('key', ''))
133+
info["key"] = info.get("key", "").encode()
135134
return info
136135

137136

ipykernel/iostream.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from jupyter_client.session import extract_header
2626

27-
from ipython_genutils import py3compat
2827

2928
#-----------------------------------------------------------------------------
3029
# Globals
@@ -288,8 +287,12 @@ class OutStream(TextIOBase):
288287

289288
def __init__(self, session, pub_thread, name, pipe=None, echo=None):
290289
if pipe is not None:
291-
warnings.warn("pipe argument to OutStream is deprecated and ignored",
292-
DeprecationWarning)
290+
warnings.warn(
291+
"pipe argument to OutStream is deprecated and ignored",
292+
" since ipykernel 4.2.3.",
293+
DeprecationWarning,
294+
stacklevel=2,
295+
)
293296
# This is necessary for compatibility with Python built-in streams
294297
self.session = session
295298
if not isinstance(pub_thread, IOPubThread):
@@ -300,7 +303,7 @@ def __init__(self, session, pub_thread, name, pipe=None, echo=None):
300303
pub_thread.start()
301304
self.pub_thread = pub_thread
302305
self.name = name
303-
self.topic = b'stream.' + py3compat.cast_bytes(name)
306+
self.topic = b"stream." + name.encode()
304307
self.parent_header = {}
305308
self._master_pid = os.getpid()
306309
self._flush_pending = False

ipykernel/kernelbase.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
from traitlets.config.configurable import SingletonConfigurable
3131
from IPython.core.error import StdinNotImplementedError
32-
from ipython_genutils import py3compat
3332
from ipykernel.jsonutil import json_clean
3433
from traitlets import (
3534
Any, Instance, Float, Dict, List, Set, Integer, Unicode, Bool,
@@ -824,7 +823,7 @@ def _topic(self, topic):
824823
"""prefixed topic for IOPub messages"""
825824
base = "kernel.%s" % self.ident
826825

827-
return py3compat.cast_bytes("%s.%s" % (base, topic))
826+
return ("%s.%s" % (base, topic)).encode()
828827

829828
_aborting = Bool(False)
830829

@@ -939,8 +938,8 @@ def _input_request(self, prompt, ident, parent, password=False):
939938
self.log.warning("Invalid Message:", exc_info=True)
940939

941940
try:
942-
value = py3compat.unicode_to_str(reply['content']['value'])
943-
except:
941+
value = reply["content"]["value"]
942+
except Exception:
944943
self.log.error("Bad input_reply: %s", parent)
945944
value = ''
946945
if value == '\x04':

ipykernel/tests/test_jsonutil.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
from .. import jsonutil
1515
from ..jsonutil import json_clean, encode_images
16-
from ipython_genutils.py3compat import unicode_to_str
1716

1817
class MyInt(object):
1918
def __int__(self):
@@ -80,14 +79,8 @@ def test_encode_images():
8079
encoded2 = json_clean(encode_images(encoded))
8180
assert encoded == encoded2
8281

83-
# test that we don't double-encode base64 str
84-
b64_str = {}
85-
for key, encoded in encoded.items():
86-
b64_str[key] = unicode_to_str(encoded)
87-
encoded3 = json_clean(encode_images(b64_str))
88-
assert encoded3 == b64_str
8982
for key, value in fmt.items():
90-
decoded = a2b_base64(encoded3[key])
83+
decoded = a2b_base64(encoded[key])
9184
assert decoded == value
9285

9386
def test_lambda():

0 commit comments

Comments
 (0)