Skip to content

Commit f1a32a8

Browse files
Merge pull request #600 from Carreau/remove-genutils
Some removal of ipython_genutils.py3compat.
2 parents d6c78de + 2052290 commit f1a32a8

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
@@ -28,7 +28,6 @@
2828

2929
from traitlets.config.configurable import SingletonConfigurable
3030
from IPython.core.error import StdinNotImplementedError
31-
from ipython_genutils import py3compat
3231
from ipykernel.jsonutil import json_clean
3332
from traitlets import (
3433
Any, Instance, Float, Dict, List, Set, Integer, Unicode, Bool,
@@ -807,7 +806,7 @@ def _topic(self, topic):
807806
"""prefixed topic for IOPub messages"""
808807
base = "kernel.%s" % self.ident
809808

810-
return py3compat.cast_bytes("%s.%s" % (base, topic))
809+
return ("%s.%s" % (base, topic)).encode()
811810

812811
_aborting = Bool(False)
813812

@@ -922,8 +921,8 @@ def _input_request(self, prompt, ident, parent, password=False):
922921
self.log.warning("Invalid Message:", exc_info=True)
923922

924923
try:
925-
value = py3compat.unicode_to_str(reply['content']['value'])
926-
except:
924+
value = reply["content"]["value"]
925+
except Exception:
927926
self.log.error("Bad input_reply: %s", parent)
928927
value = ''
929928
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)