MCPcopy Create free account
hub / github.com/hynek/structlog / _deprecated

Function _deprecated

src/structlog/threadlocal.py:50–78  ·  view source on GitHub ↗

Raise a warning with best-effort stacklevel adjustment.

()

Source from the content-addressed store, hash-verified

48
49
50def _deprecated() -> None:
51 """
52 Raise a warning with best-effort stacklevel adjustment.
53 """
54 callsite = ""
55
56 with contextlib.suppress(Exception):
57 f = sys._getframe()
58 callsite = f.f_back.f_back.f_globals[ # type: ignore[union-attr]
59 "__name__"
60 ]
61
62 # Avoid double warnings if TL functions call themselves.
63 if callsite == "structlog.threadlocal":
64 return
65
66 stacklevel = 3
67 # If a function is used as a decorator, we need to add two stack levels.
68 # This logic will probably break eventually, but it's not worth any more
69 # complexity.
70 if callsite == "contextlib":
71 stacklevel += 2
72
73 warnings.warn(
74 "`structlog.threadlocal` is deprecated, please use "
75 "`structlog.contextvars` instead.",
76 DeprecationWarning,
77 stacklevel=stacklevel,
78 )
79
80
81def wrap_dict(dict_class: type[Context]) -> type[Context]:

Callers 10

wrap_dictFunction · 0.85
as_immutableFunction · 0.85
tmp_bindFunction · 0.85
get_threadlocalFunction · 0.85
get_merged_threadlocalFunction · 0.85
merge_threadlocalFunction · 0.85
clear_threadlocalFunction · 0.85
bind_threadlocalFunction · 0.85
unbind_threadlocalFunction · 0.85
bound_threadlocalFunction · 0.85

Calls 1

warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…