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

Remove u-prefix from strings #538

Merged
merged 1 commit into from
Aug 18, 2020
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
10 changes: 5 additions & 5 deletions ipykernel/displayhook.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ def __call__(self, obj):
builtin_mod._ = obj
sys.stdout.flush()
sys.stderr.flush()
contents = {u'execution_count': self.get_execution_count(),
u'data': {'text/plain': repr(obj)},
u'metadata': {}}
self.session.send(self.pub_socket, u'execute_result', contents,
contents = {'execution_count': self.get_execution_count(),
'data': {'text/plain': repr(obj)},
'metadata': {}}
self.session.send(self.pub_socket, 'execute_result', contents,
parent=self.parent_header, ident=self.topic)

def set_parent(self, parent):
Expand All @@ -58,7 +58,7 @@ def set_parent(self, parent):
self.parent_header = extract_header(parent)

def start_displayhook(self):
self.msg = self.session.msg(u'execute_result', {
self.msg = self.session.msg('execute_result', {
'data': {},
'metadata': {},
}, parent=self.parent_header)
Expand Down
6 changes: 3 additions & 3 deletions ipykernel/inprocess/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def _input_request(self, prompt, ident, parent, password=False):

# Send the input request.
content = json_clean(dict(prompt=prompt, password=password))
msg = self.session.msg(u'input_request', content, parent)
msg = self.session.msg('input_request', content, parent)
for frontend in self.frontends:
if frontend.session.session == parent['header']['session']:
frontend.stdin_channel.call_handlers(msg)
Expand Down Expand Up @@ -148,11 +148,11 @@ def _default_shell_class(self):

@default('stdout')
def _default_stdout(self):
return OutStream(self.session, self.iopub_thread, u'stdout')
return OutStream(self.session, self.iopub_thread, 'stdout')

@default('stderr')
def _default_stderr(self):
return OutStream(self.session, self.iopub_thread, u'stderr')
return OutStream(self.session, self.iopub_thread, 'stderr')

#-----------------------------------------------------------------------------
# Interactive shell subclass
Expand Down
6 changes: 3 additions & 3 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,8 @@ def _flush(self):
# since pub_thread is itself fork-safe.
# There should be a better way to do this.
self.session.pid = os.getpid()
content = {u'name':self.name, u'text':data}
self.session.send(self.pub_thread, u'stream', content=content,
content = {'name':self.name, 'text':data}
self.session.send(self.pub_thread, 'stream', content=content,
parent=self.parent_header, ident=self.topic)

def write(self, string):
Expand Down Expand Up @@ -428,7 +428,7 @@ def _flush_buffer(self):

This should only be called in the IO thread.
"""
data = u''
data = ''
if self._buffer is not None:
buf = self._buffer
self._new_buffer()
Expand Down
26 changes: 13 additions & 13 deletions ipykernel/ipkernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,14 +313,14 @@ def run_cell(*args, **kwargs):
err = res.error_in_exec

if res.success:
reply_content[u'status'] = u'ok'
reply_content['status'] = 'ok'
else:
reply_content[u'status'] = u'error'
reply_content['status'] = 'error'

reply_content.update({
u'traceback': shell._last_traceback or [],
u'ename': unicode_type(type(err).__name__),
u'evalue': safe_unicode(err),
'traceback': shell._last_traceback or [],
'ename': unicode_type(type(err).__name__),
'evalue': safe_unicode(err),
})

# FIXME: deprecated piece for ipyparallel (remove in 5.0):
Expand All @@ -339,16 +339,16 @@ def run_cell(*args, **kwargs):
# At this point, we can tell whether the main code execution succeeded
# or not. If it did, we proceed to evaluate user_expressions
if reply_content['status'] == 'ok':
reply_content[u'user_expressions'] = \
reply_content['user_expressions'] = \
shell.user_expressions(user_expressions or {})
else:
# If there was an error, don't even try to compute expressions
reply_content[u'user_expressions'] = {}
reply_content['user_expressions'] = {}

# Payloads should be retrieved regardless of outcome, so we can both
# recover partial output (that could have been generated early in a
# block, before an error) and always clear the payload system.
reply_content[u'payload'] = shell.payload_manager.read_payload()
reply_content['payload'] = shell.payload_manager.read_payload()
# Be aggressive about clearing the payload because we don't want
# it to sit in memory until the next execute_request comes in.
shell.payload_manager.clear_payload()
Expand Down Expand Up @@ -504,16 +504,16 @@ def do_apply(self, content, bufs, msg_id, reply_metadata):
# invoke IPython traceback formatting
shell.showtraceback()
reply_content = {
u'traceback': shell._last_traceback or [],
u'ename': unicode_type(type(e).__name__),
u'evalue': safe_unicode(e),
'traceback': shell._last_traceback or [],
'ename': unicode_type(type(e).__name__),
'evalue': safe_unicode(e),
}
# FIXME: deprecated piece for ipyparallel (remove in 5.0):
e_info = dict(engine_uuid=self.ident, engine_id=self.int_id, method='apply')
reply_content['engine_info'] = e_info

self.send_response(self.iopub_socket, u'error', reply_content,
ident=self._topic('error'))
self.send_response(self.iopub_socket, 'error', reply_content,
ident=self._topic('error'))
self.log.info("Exception in apply request:\n%s", '\n'.join(reply_content['traceback']))
result_buf = []
reply_content['status'] = 'error'
Expand Down
4 changes: 2 additions & 2 deletions ipykernel/kernelapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,12 @@ def init_io(self):
e_stderr = None if self.quiet else sys.__stderr__

sys.stdout = outstream_factory(self.session, self.iopub_thread,
u'stdout',
'stdout',
echo=e_stdout)
if sys.stderr is not None:
sys.stderr.flush()
sys.stderr = outstream_factory(self.session, self.iopub_thread,
u'stderr',
'stderr',
echo=e_stderr)
if self.displayhook_class:
displayhook_factory = import_item(str(self.displayhook_class))
Expand Down
46 changes: 23 additions & 23 deletions ipykernel/kernelbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ def dispatch_control(self, msg):

# Set the parent message for side effects.
self.set_parent(idents, msg)
self._publish_status(u'busy')
self._publish_status('busy')
if self._aborting:
self._send_abort_reply(self.control_stream, msg, idents)
self._publish_status(u'idle')
self._publish_status('idle')
return

header = msg['header']
Expand All @@ -204,7 +204,7 @@ def dispatch_control(self, msg):

sys.stdout.flush()
sys.stderr.flush()
self._publish_status(u'idle')
self._publish_status('idle')
# flush to ensure reply is sent
self.control_stream.flush(zmq.POLLOUT)

Expand Down Expand Up @@ -234,11 +234,11 @@ def dispatch_shell(self, stream, msg):

# Set the parent message for side effects.
self.set_parent(idents, msg)
self._publish_status(u'busy')
self._publish_status('busy')

if self._aborting:
self._send_abort_reply(stream, msg, idents)
self._publish_status(u'idle')
self._publish_status('idle')
# flush to ensure reply is sent before
# handling the next request
stream.flush(zmq.POLLOUT)
Expand Down Expand Up @@ -276,7 +276,7 @@ def dispatch_shell(self, stream, msg):

sys.stdout.flush()
sys.stderr.flush()
self._publish_status(u'idle')
self._publish_status('idle')
# flush to ensure reply is sent before
# handling the next request
stream.flush(zmq.POLLOUT)
Expand Down Expand Up @@ -456,16 +456,16 @@ def record_ports(self, ports):
def _publish_execute_input(self, code, parent, execution_count):
"""Publish the code request on the iopub stream."""

self.session.send(self.iopub_socket, u'execute_input',
{u'code':code, u'execution_count': execution_count},
parent=parent, ident=self._topic('execute_input')
self.session.send(self.iopub_socket, 'execute_input',
{'code':code, 'execution_count': execution_count},
parent=parent, ident=self._topic('execute_input')
)

def _publish_status(self, status, parent=None):
"""send status (busy/idle) on IOPub"""
self.session.send(self.iopub_socket,
u'status',
{u'execution_state': status},
'status',
{'execution_state': status},
parent=parent or self._parent_header,
ident=self._topic('status'),
)
Expand Down Expand Up @@ -518,10 +518,10 @@ def execute_request(self, stream, ident, parent):
"""handle an execute_request"""

try:
content = parent[u'content']
code = py3compat.cast_unicode_py2(content[u'code'])
silent = content[u'silent']
store_history = content.get(u'store_history', not silent)
content = parent['content']
code = py3compat.cast_unicode_py2(content['code'])
silent = content['silent']
store_history = content.get('store_history', not silent)
user_expressions = content.get('user_expressions', {})
allow_stdin = content.get('allow_stdin', False)
except:
Expand Down Expand Up @@ -559,13 +559,13 @@ def execute_request(self, stream, ident, parent):
reply_content = json_clean(reply_content)
metadata = self.finish_metadata(parent, metadata, reply_content)

reply_msg = self.session.send(stream, u'execute_reply',
reply_msg = self.session.send(stream, 'execute_reply',
reply_content, parent, metadata=metadata,
ident=ident)

self.log.debug("%s", reply_msg)

if not silent and reply_msg['content']['status'] == u'error' and stop_on_error:
if not silent and reply_msg['content']['status'] == 'error' and stop_on_error:
yield self._abort_queues()

def do_execute(self, code, silent, store_history=True,
Expand Down Expand Up @@ -681,9 +681,9 @@ def comm_info_request(self, stream, ident, parent):
@gen.coroutine
def shutdown_request(self, stream, ident, parent):
content = yield gen.maybe_future(self.do_shutdown(parent['content']['restart']))
self.session.send(stream, u'shutdown_reply', content, parent, ident=ident)
self.session.send(stream, 'shutdown_reply', content, parent, ident=ident)
# same content, but different msg_id for broadcasting on IOPub
self._shutdown_message = self.session.msg(u'shutdown_reply',
self._shutdown_message = self.session.msg('shutdown_reply',
content, parent
)

Expand Down Expand Up @@ -722,8 +722,8 @@ def do_is_complete(self, code):
def apply_request(self, stream, ident, parent):
self.log.warning("apply_request is deprecated in kernel_base, moving to ipyparallel.")
try:
content = parent[u'content']
bufs = parent[u'buffers']
content = parent['content']
bufs = parent['buffers']
msg_id = parent['header']['msg_id']
except:
self.log.error("Got bad msg: %s", parent, exc_info=True)
Expand All @@ -739,7 +739,7 @@ def apply_request(self, stream, ident, parent):

md = self.finish_metadata(parent, md, reply_content)

self.session.send(stream, u'apply_reply', reply_content,
self.session.send(stream, 'apply_reply', reply_content,
parent=parent, ident=ident,buffers=result_buf, metadata=md)

def do_apply(self, content, bufs, msg_id, reply_metadata):
Expand Down Expand Up @@ -880,7 +880,7 @@ def _input_request(self, prompt, ident, parent, password=False):

# Send the input request.
content = json_clean(dict(prompt=prompt, password=password))
self.session.send(self.stdin_socket, u'input_request', content, parent,
self.session.send(self.stdin_socket, 'input_request', content, parent,
ident=ident)

# Await a response.
Expand Down
6 changes: 3 additions & 3 deletions ipykernel/tests/test_embed_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_embed_kernel_basic():
msg_id = client.execute("c=a*2")
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
assert content['status'] == u'ok'
assert content['status'] == 'ok'

# oinfo c (should be 10)
msg_id = client.inspect('c')
Expand Down Expand Up @@ -134,15 +134,15 @@ def test_embed_kernel_namespace():
content = msg['content']
assert content['found']
text = content['data']['text/plain']
assert u'5' in text
assert '5' in text

# oinfo b (str)
msg_id = client.inspect('b')
msg = client.get_shell_msg(block=True, timeout=TIMEOUT)
content = msg['content']
assert content['found']
text = content['data']['text/plain']
assert u'hi there' in text
assert 'hi there' in text

# oinfo c (undefined)
msg_id = client.inspect('c')
Expand Down
2 changes: 1 addition & 1 deletion ipykernel/tests/test_jsonutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ def test_exception():


def test_unicode_dict():
data = {u'üniço∂e': u'üniço∂e'}
data = {'üniço∂e': 'üniço∂e'}
clean = jsonutil.json_clean(data)
assert data == clean
18 changes: 9 additions & 9 deletions ipykernel/tests/test_kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def test_raw_input():
code = 'print({input_f}("{theprompt}"))'.format(**locals())
msg_id = kc.execute(code, allow_stdin=True)
msg = kc.get_stdin_msg(block=True, timeout=TIMEOUT)
assert msg['header']['msg_type'] == u'input_request'
assert msg['header']['msg_type'] == 'input_request'
content = msg['content']
assert content['prompt'] == theprompt
text = "some text"
Expand All @@ -188,7 +188,7 @@ def test_eval_input():
code = 'print(input("{theprompt}"))'.format(**locals())
msg_id = kc.execute(code, allow_stdin=True)
msg = kc.get_stdin_msg(block=True, timeout=TIMEOUT)
assert msg['header']['msg_type'] == u'input_request'
assert msg['header']['msg_type'] == 'input_request'
content = msg['content']
assert content['prompt'] == theprompt
kc.input("1+1")
Expand All @@ -203,23 +203,23 @@ def test_save_history():
# unicode problems on Python 2.
with kernel() as kc, TemporaryDirectory() as td:
file = os.path.join(td, 'hist.out')
execute(u'a=1', kc=kc)
execute('a=1', kc=kc)
wait_for_idle(kc)
execute(u'b=u"abcþ"', kc=kc)
execute('b="abcþ"', kc=kc)
wait_for_idle(kc)
_, reply = execute("%hist -f " + file, kc=kc)
assert reply['status'] == 'ok'
with io.open(file, encoding='utf-8') as f:
content = f.read()
assert u'a=1' in content
assert u'b=u"abcþ"' in content
assert 'a=1' in content
assert 'b="abcþ"' in content


@dec.skip_without('faulthandler')
def test_smoke_faulthandler():
with kernel() as kc:
# Note: faulthandler.register is not available on windows.
code = u'\n'.join([
code = '\n'.join([
'import sys',
'import faulthandler',
'import signal',
Expand Down Expand Up @@ -262,7 +262,7 @@ def test_is_complete():
@dec.skipif(sys.platform != 'win32', "only run on Windows")
def test_complete():
with kernel() as kc:
execute(u'a = 1', kc=kc)
execute('a = 1', kc=kc)
wait_for_idle(kc)
cell = 'import IPython\nb = a.'
kc.complete(cell)
Expand Down Expand Up @@ -355,7 +355,7 @@ def test_shutdown():
"""Kernel exits after polite shutdown_request"""
with new_kernel() as kc:
km = kc.parent
execute(u'a = 1', kc=kc)
execute('a = 1', kc=kc)
wait_for_idle(kc)
kc.shutdown()
for i in range(300): # 30s timeout
Expand Down
Loading