MCPcopy Create free account
hub / github.com/ipython/traitlets / deprecated_method

Function deprecated_method

traitlets/utils/warnings.py:17–45  ·  view source on GitHub ↗

Show deprecation warning about a magic method definition. Uses warn_explicit to bind warning to method definition instead of triggering code, which isn't relevant.

(method: t.Any, cls: t.Any, method_name: str, msg: str)

Source from the content-addressed store, hash-verified

15
16
17def deprecated_method(method: t.Any, cls: t.Any, method_name: str, msg: str) -> None:
18 """Show deprecation warning about a magic method definition.
19
20 Uses warn_explicit to bind warning to method definition instead of triggering code,
21 which isn't relevant.
22 """
23 warn_msg = f"{cls.__name__}.{method_name} is deprecated in traitlets 4.1: {msg}"
24
25 for parent in inspect.getmro(cls):
26 if method_name in parent.__dict__:
27 cls = parent
28 break
29 # limit deprecation messages to once per package
30 package_name = cls.__module__.split(".", 1)[0]
31 key = (package_name, msg)
32 if not should_warn(key):
33 return
34 try:
35 fname = inspect.getsourcefile(method) or "<unknown>"
36 lineno = inspect.getsourcelines(method)[1] or 0
37 except (OSError, TypeError) as e:
38 # Failed to inspect for some reason
39 warn(
40 warn_msg + ("\n(inspection failed) %s" % e),
41 DeprecationWarning,
42 stacklevel=2,
43 )
44 else:
45 warnings.warn_explicit(warn_msg, DeprecationWarning, fname, lineno)
46
47
48_deprecations_shown = set()

Callers 3

_cross_validateMethod · 0.85
_notify_observersMethod · 0.85
_register_validatorMethod · 0.85

Calls 2

should_warnFunction · 0.85
warnFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…