MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _warnings_warn

Function _warnings_warn

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

Source from the content-addressed store, hash-verified

1922
1923
1924def _warnings_warn(
1925 message: Union[str, Warning],
1926 category: Optional[Type[Warning]] = None,
1927 stacklevel: int = 2,
1928) -> None:
1929
1930 if category is None and isinstance(message, Warning):
1931 category = type(message)
1932
1933 # adjust the given stacklevel to be outside of SQLAlchemy
1934 try:
1935 frame = sys._getframe(stacklevel)
1936 except ValueError:
1937 # being called from less than 3 (or given) stacklevels, weird,
1938 # but don't crash
1939 stacklevel = 0
1940 except:
1941 # _getframe() doesn't work, weird interpreter issue, weird,
1942 # ok, but don't crash
1943 stacklevel = 0
1944 else:
1945 stacklevel_found = warning_tag_found = False
1946 while frame is not None:
1947 # using __name__ here requires that we have __name__ in the
1948 # __globals__ of the decorated string functions we make also.
1949 # we generate this using {"__name__": fn.__module__}
1950 if not stacklevel_found and not re.match(
1951 _not_sa_pattern, frame.f_globals.get("__name__", "")
1952 ):
1953 # stop incrementing stack level if an out-of-SQLA line
1954 # were found.
1955 stacklevel_found = True
1956
1957 # however, for the warning tag thing, we have to keep
1958 # scanning up the whole traceback
1959
1960 if frame.f_code in _warning_tags:
1961 warning_tag_found = True
1962 _suffix, _category = _warning_tags[frame.f_code]
1963 category = category or _category
1964 message = f"{message} ({_suffix})"
1965
1966 frame = frame.f_back # type: ignore[assignment]
1967
1968 if not stacklevel_found:
1969 stacklevel += 1
1970 elif stacklevel_found and warning_tag_found:
1971 break
1972
1973 if category is not None:
1974 warnings.warn(message, category, stacklevel=stacklevel + 1)
1975 else:
1976 warnings.warn(message, stacklevel=stacklevel + 1)
1977
1978
1979def 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