MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _warnings_warn

Function _warnings_warn

lib/sqlalchemy/util/langhelpers.py:1834–1882  ·  view source on GitHub ↗
(
    message: Union[str, Warning],
    category: Optional[Type[Warning]] = None,
    stacklevel: int = 2,
)

Source from the content-addressed store, hash-verified

1832
1833
1834def _warnings_warn(
1835 message: Union[str, Warning],
1836 category: Optional[Type[Warning]] = None,
1837 stacklevel: int = 2,
1838) -> None:
1839 # adjust the given stacklevel to be outside of SQLAlchemy
1840 try:
1841 frame = sys._getframe(stacklevel)
1842 except ValueError:
1843 # being called from less than 3 (or given) stacklevels, weird,
1844 # but don't crash
1845 stacklevel = 0
1846 except:
1847 # _getframe() doesn't work, weird interpreter issue, weird,
1848 # ok, but don't crash
1849 stacklevel = 0
1850 else:
1851 stacklevel_found = warning_tag_found = False
1852 while frame is not None:
1853 # using __name__ here requires that we have __name__ in the
1854 # __globals__ of the decorated string functions we make also.
1855 # we generate this using {"__name__": fn.__module__}
1856 if not stacklevel_found and not re.match(
1857 _not_sa_pattern, frame.f_globals.get("__name__", "")
1858 ):
1859 # stop incrementing stack level if an out-of-SQLA line
1860 # were found.
1861 stacklevel_found = True
1862
1863 # however, for the warning tag thing, we have to keep
1864 # scanning up the whole traceback
1865
1866 if frame.f_code in _warning_tags:
1867 warning_tag_found = True
1868 _suffix, _category = _warning_tags[frame.f_code]
1869 category = category or _category
1870 message = f"{message} ({_suffix})"
1871
1872 frame = frame.f_back # type: ignore[assignment]
1873
1874 if not stacklevel_found:
1875 stacklevel += 1
1876 elif stacklevel_found and warning_tag_found:
1877 break
1878
1879 if category is not None:
1880 warnings.warn(message, category, stacklevel=stacklevel + 1)
1881 else:
1882 warnings.warn(message, stacklevel=stacklevel + 1)
1883
1884
1885def only_once(

Callers 4

warn_test_suiteFunction · 0.85
_warn_with_versionFunction · 0.85
warnFunction · 0.85
warn_limitedFunction · 0.85

Calls 3

matchMethod · 0.45
getMethod · 0.45
warnMethod · 0.45

Tested by

no test coverage detected