Skip to content

Commit

Permalink
Merge pull request ipython#761 from Carreau/better-deprecation
Browse files Browse the repository at this point in the history
Update some warnings with instructions and version number.
  • Loading branch information
minrk authored Sep 1, 2021
2 parents be9d40d + cf2d56e commit 3c6037f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions ipykernel/iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,27 @@ def __getattr__(self, attr):
# don't wrap magic methods
super(BackgroundSocket, self).__getattr__(attr)
if hasattr(self.io_thread.socket, attr):
warnings.warn("Accessing zmq Socket attribute %s on BackgroundSocket" % attr,
DeprecationWarning, stacklevel=2)
warnings.warn(
"Accessing zmq Socket attribute {attr} on BackgroundSocket"
" is deprecated since ipykernel 4.3.0"
" use .io_thread.socket.{attr}".format(attr=attr),
DeprecationWarning,
stacklevel=2,
)
return getattr(self.io_thread.socket, attr)
super(BackgroundSocket, self).__getattr__(attr)

def __setattr__(self, attr, value):
if attr == 'io_thread' or (attr.startswith('__' and attr.endswith('__'))):
super(BackgroundSocket, self).__setattr__(attr, value)
else:
warnings.warn("Setting zmq Socket attribute %s on BackgroundSocket" % attr,
DeprecationWarning, stacklevel=2)
warnings.warn(
"Setting zmq Socket attribute {attr} on BackgroundSocket"
" is deprecated since ipykernel 4.3.0"
" use .io_thread.socket.{attr}".format(attr=attr),
DeprecationWarning,
stacklevel=2,
)
setattr(self.io_thread.socket, attr, value)

def send(self, msg, *args, **kwargs):
Expand Down

0 comments on commit 3c6037f

Please sign in to comment.