Skip to content

Commit b7f14bf

Browse files
authored
Merge pull request #547 from jack1142/fix_few_depr_warnings
Fix stack levels for ipykernel's deprecation warnings and stop using some deprecated APIs
2 parents 6ba7540 + c943abe commit b7f14bf

File tree

8 files changed

+65
-18
lines changed

8 files changed

+65
-18
lines changed

ipykernel/codeutil.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
# Distributed under the terms of the Modified BSD License.
1313

1414
import warnings
15-
warnings.warn("ipykernel.codeutil is deprecated since IPykernel 4.3.1. It has moved to ipyparallel.serialize", DeprecationWarning)
15+
warnings.warn("ipykernel.codeutil is deprecated since IPykernel 4.3.1. It has moved to ipyparallel.serialize",
16+
DeprecationWarning,
17+
stacklevel=2
18+
)
1619

1720
import copyreg
1821
import sys

ipykernel/datapub.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22
"""
33

44
import warnings
5-
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", DeprecationWarning)
5+
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub",
6+
DeprecationWarning,
7+
stacklevel=2
8+
)
69

710
# Copyright (c) IPython Development Team.
811
# Distributed under the terms of the Modified BSD License.
912

1013
from traitlets.config import Configurable
1114
from traitlets import Instance, Dict, CBytes, Any
1215
from ipykernel.jsonutil import json_clean
13-
from ipykernel.serialize import serialize_object
16+
try:
17+
# available since ipyparallel 5.0.0
18+
from ipyparallel.serialize import serialize_object
19+
except ImportError:
20+
# Deprecated since ipykernel 4.3.0
21+
from ipykernel.serialize import serialize_object
1422
from jupyter_client.session import Session, extract_header
1523

1624

@@ -56,7 +64,10 @@ def publish_data(data):
5664
data : dict
5765
The data to be published. Think of it as a namespace.
5866
"""
59-
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub", DeprecationWarning)
67+
warnings.warn("ipykernel.datapub is deprecated. It has moved to ipyparallel.datapub",
68+
DeprecationWarning,
69+
stacklevel=2
70+
)
6071

6172
from ipykernel.zmqshell import ZMQInteractiveShell
6273
ZMQInteractiveShell.instance().data_pub.publish_data(data)

ipykernel/iostream.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
from io import StringIO, TextIOBase
1515

1616
import zmq
17-
from zmq.eventloop.ioloop import IOLoop
17+
if zmq.pyzmq_version_info() >= (17, 0):
18+
from tornado.ioloop import IOLoop
19+
else:
20+
# deprecated since pyzmq 17
21+
from zmq.eventloop.ioloop import IOLoop
1822
from zmq.eventloop.zmqstream import ZMQStream
1923

2024
from jupyter_client.session import extract_header

ipykernel/ipkernel.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from ipython_genutils.py3compat import safe_unicode
1313
from IPython.utils.tokenutil import token_at_cursor, line_at_cursor
1414
from tornado import gen
15-
from traitlets import Instance, Type, Any, List, Bool
15+
from traitlets import Instance, Type, Any, List, Bool, observe, observe_compat
1616

1717
from .comm import CommManager
1818
from .kernelbase import Kernel as KernelBase
@@ -43,14 +43,18 @@ class IPythonKernel(KernelBase):
4343
).tag(config=True)
4444

4545
user_module = Any()
46-
def _user_module_changed(self, name, old, new):
46+
@observe('user_module')
47+
@observe_compat
48+
def _user_module_changed(self, change):
4749
if self.shell is not None:
48-
self.shell.user_module = new
50+
self.shell.user_module = change['new']
4951

5052
user_ns = Instance(dict, args=None, allow_none=True)
51-
def _user_ns_changed(self, name, old, new):
53+
@observe('user_ns')
54+
@observe_compat
55+
def _user_ns_changed(self, change):
5256
if self.shell is not None:
53-
self.shell.user_ns = new
57+
self.shell.user_ns = change['new']
5458
self.shell.init_user_ns()
5559

5660
# A reference to the Python builtin 'raw_input' function.

ipykernel/log.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
from zmq.log.handlers import PUBHandler
44

55
import warnings
6-
warnings.warn("ipykernel.log is deprecated. It has moved to ipyparallel.engine.log", DeprecationWarning)
6+
warnings.warn("ipykernel.log is deprecated. It has moved to ipyparallel.engine.log",
7+
DeprecationWarning
8+
stacklevel=2
9+
)
710

811
class EnginePUBHandler(PUBHandler):
912
"""A simple PUBHandler subclass that sets root_topic"""

ipykernel/pickleutil.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
# Distributed under the terms of the Modified BSD License.
55

66
import warnings
7-
warnings.warn("ipykernel.pickleutil is deprecated. It has moved to ipyparallel.", DeprecationWarning)
7+
warnings.warn("ipykernel.pickleutil is deprecated. It has moved to ipyparallel.",
8+
DeprecationWarning,
9+
stacklevel=2
10+
)
811

912
import copy
1013
import sys

ipykernel/serialize.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,28 @@
44
# Distributed under the terms of the Modified BSD License.
55

66
import warnings
7-
warnings.warn("ipykernel.serialize is deprecated. It has moved to ipyparallel.serialize", DeprecationWarning)
7+
warnings.warn("ipykernel.serialize is deprecated. It has moved to ipyparallel.serialize",
8+
DeprecationWarning,
9+
stacklevel=2
10+
)
811

912
import pickle
1013

1114
from itertools import chain
1215

13-
from ipykernel.pickleutil import (
14-
can, uncan, can_sequence, uncan_sequence, CannedObject,
15-
istype, sequence_types, PICKLE_PROTOCOL,
16-
)
16+
try:
17+
# available since ipyparallel 5.0.0
18+
from ipyparallel.serialize.canning import (
19+
can, uncan, can_sequence, uncan_sequence, CannedObject,
20+
istype, sequence_types,
21+
)
22+
from ipyparallel.serialize.serialize import PICKLE_PROTOCOL
23+
except ImportError:
24+
# Deprecated since ipykernel 4.3.0
25+
from ipykernel.pickleutil import (
26+
can, uncan, can_sequence, uncan_sequence, CannedObject,
27+
istype, sequence_types, PICKLE_PROTOCOL,
28+
)
1729
from jupyter_client.session import MAX_ITEMS, MAX_BYTES
1830

1931

ipykernel/zmqshell.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@
4949
from jupyter_core.paths import jupyter_runtime_dir
5050
from jupyter_client.session import extract_header, Session
5151

52+
try:
53+
# available since ipyparallel 5.0.0
54+
from ipyparallel.engine.datapub import ZMQDataPublisher
55+
except ImportError:
56+
# Deprecated since ipykernel 4.3.0
57+
from ipykernel.datapub import ZMQDataPublisher
58+
5259
#-----------------------------------------------------------------------------
5360
# Functions and classes
5461
#-----------------------------------------------------------------------------
@@ -438,7 +445,7 @@ class ZMQInteractiveShell(InteractiveShell):
438445

439446
displayhook_class = Type(ZMQShellDisplayHook)
440447
display_pub_class = Type(ZMQDisplayPublisher)
441-
data_pub_class = Type('ipykernel.datapub.ZMQDataPublisher')
448+
data_pub_class = Type(ZMQDataPublisher)
442449
kernel = Any()
443450
parent_header = Any()
444451

0 commit comments

Comments
 (0)