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)
| 15 | |
| 16 | |
| 17 | def 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() |
no test coverage detected
searching dependent graphs…