Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5dd7087

Browse files
committed
Add stacklevel=2 to warn function
1 parent 585eb89 commit 5dd7087

10 files changed

Lines changed: 16 additions & 15 deletions

File tree

IPython/core/interactiveshell.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,10 @@ def _exiter_default(self):
354354
@observe('prompt_in1', 'prompt_in2', 'prompt_out', 'prompt_pad_left')
355355
def _prompt_trait_changed(self, change):
356356
name = change['name']
357-
warn("InteractiveShell.{name} is deprecated since IPython 4.0 and ignored since 5.0, set TerminalInteractiveShell.prompts object directly.".format(
358-
name=name)
359-
)
357+
warn("InteractiveShell.{name} is deprecated since IPython 4.0"
358+
" and ignored since 5.0, set TerminalInteractiveShell.prompts"
359+
" object directly.".format(name=name))
360+
360361
# protect against weird cases where self.config may not exist:
361362

362363
show_rewritten_input = Bool(True,
@@ -811,7 +812,7 @@ def set_hook(self,name,hook, priority=50, str_key=None, re_key=None,
811812

812813
if _warn_deprecated and (name in IPython.core.hooks.deprecated):
813814
alternative = IPython.core.hooks.deprecated[name]
814-
warn("Hook {} is deprecated. Use {} instead.".format(name, alternative))
815+
warn("Hook {} is deprecated. Use {} instead.".format(name, alternative), stacklevel=2)
815816

816817
if not dp:
817818
dp = IPython.core.hooks.CommandChainDispatcher()
@@ -839,7 +840,7 @@ def register_post_execute(self, func):
839840
Register a function for calling after code execution.
840841
"""
841842
warn("ip.register_post_execute is deprecated, use "
842-
"ip.events.register('post_run_cell', func) instead.")
843+
"ip.events.register('post_run_cell', func) instead.", stacklevel=2)
843844
self.events.register('post_run_cell', func)
844845

845846
def _clear_warning_registry(self):

IPython/utils/PyColorize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
from StringIO import StringIO
5555

5656
#############################################################################
57-
### Python Source Parser (does Hilighting)
57+
### Python Source Parser (does Highlighting)
5858
#############################################################################
5959

6060
_KEYWORD = token.NT_OFFSET + 1

IPython/utils/daemonize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from warnings import warn
22

3-
warn("IPython.utils.daemonize has moved to ipyparallel.apps.daemonize")
3+
warn("IPython.utils.daemonize has moved to ipyparallel.apps.daemonize", stacklevel=2)
44
from ipyparallel.apps.daemonize import daemonize

IPython/utils/eventful.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
from warnings import warn
33

4-
warn("IPython.utils.eventful has moved to traitlets.eventful")
4+
warn("IPython.utils.eventful has moved to traitlets.eventful", stacklevel=2)
55

66
from traitlets.eventful import *

IPython/utils/io.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ def temp_pyfile(src, ext='.py'):
207207

208208
def atomic_writing(*args, **kwargs):
209209
"""DEPRECATED: moved to notebook.services.contents.fileio"""
210-
warn("IPython.utils.io.atomic_writing has moved to notebook.services.contents.fileio")
210+
warn("IPython.utils.io.atomic_writing has moved to notebook.services.contents.fileio", stacklevel=2)
211211
from notebook.services.contents.fileio import atomic_writing
212212
return atomic_writing(*args, **kwargs)
213213

@@ -234,6 +234,6 @@ def raw_print_err(*args, **kw):
234234

235235
def unicode_std_stream(stream='stdout'):
236236
"""DEPRECATED, moved to nbconvert.utils.io"""
237-
warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io")
237+
warn("IPython.utils.io.unicode_std_stream has moved to nbconvert.utils.io", stacklevel=2)
238238
from nbconvert.utils.io import unicode_std_stream
239239
return unicode_std_stream(stream)

IPython/utils/jsonutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from warnings import warn
22

3-
warn("IPython.utils.jsonutil has moved to jupyter_client.jsonutil")
3+
warn("IPython.utils.jsonutil has moved to jupyter_client.jsonutil", stacklevel=2)
44

55
from jupyter_client.jsonutil import *

IPython/utils/localinterfaces.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from warnings import warn
22

3-
warn("IPython.utils.localinterfaces has moved to jupyter_client.localinterfaces")
3+
warn("IPython.utils.localinterfaces has moved to jupyter_client.localinterfaces", stacklevel=2)
44

55
from jupyter_client.localinterfaces import *

IPython/utils/log.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
from warnings import warn
33

4-
warn("IPython.utils.log has moved to traitlets.log")
4+
warn("IPython.utils.log has moved to traitlets.log", stacklevel=2)
55

66
from traitlets.log import *

IPython/utils/pickleutil.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from warnings import warn
22

3-
warn("IPython.utils.pickleutil has moved to ipykernel.pickleutil")
3+
warn("IPython.utils.pickleutil has moved to ipykernel.pickleutil", stacklevel=2)
44

55
from ipykernel.pickleutil import *

IPython/utils/traitlets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
from warnings import warn
33

4-
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
4+
warn("IPython.utils.traitlets has moved to a top-level traitlets package.", stacklevel=2)
55

66
from traitlets import *

0 commit comments

Comments
 (0)