Skip to content

Commit 8c35076

Browse files
add option to disable accurate warning file and line location (Fixes #3003)
1 parent fe5c437 commit 8c35076

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

elasticsearch/compat.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
# under the License.
1717

1818
import inspect
19+
import os
1920
import sys
2021
from pathlib import Path
2122
from typing import Tuple, Type, Union
2223

2324
string_types: Tuple[Type[str], Type[bytes]] = (str, bytes)
2425

26+
DISABLE_WARN_STACKLEVEL_ENV_VAR = "DISABLE_WARN_STACKLEVEL"
27+
2528

2629
def to_str(x: Union[str, bytes], encoding: str = "ascii") -> str:
2730
if not isinstance(x, str):
@@ -37,6 +40,8 @@ def to_bytes(x: Union[str, bytes], encoding: str = "ascii") -> bytes:
3740

3841
def warn_stacklevel() -> int:
3942
"""Dynamically determine warning stacklevel for warnings based on the call stack"""
43+
if os.environ.get(DISABLE_WARN_STACKLEVEL_ENV_VAR) in ['1', 'true', 'True']:
44+
return 0
4045
try:
4146
# Grab the root module from the current module '__name__'
4247
module_name = __name__.partition(".")[0]

0 commit comments

Comments
 (0)