From 254a697de2db16d07a4d100295b6d89b1b2928ec Mon Sep 17 00:00:00 2001 From: zach Date: Fri, 10 Apr 2026 23:57:10 -0700 Subject: [PATCH] Add missing stacklevel=2 to 9 warnings.warn() calls Without stacklevel, warnings.warn() reports the location of the warn() call itself rather than the caller's location, making it harder for users to identify the source of the warning in their own code. This adds stacklevel=2 to all 9 warnings.warn() calls across 7 files that were missing it. --- dash/_callback_context.py | 3 +++ dash/dash.py | 3 ++- dash/development/_jl_components_generation.py | 3 ++- dash/development/_r_components_generation.py | 3 ++- dash/development/base_component.py | 2 +- dash/resources.py | 3 ++- dash/testing/browser.py | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/dash/_callback_context.py b/dash/_callback_context.py index 09faf6f9a3..f4e12693a7 100644 --- a/dash/_callback_context.py +++ b/dash/_callback_context.py @@ -177,6 +177,7 @@ def outputs_list(self): warnings.warn( "outputs_list is deprecated, use outputs_grouping instead", DeprecationWarning, + stacklevel=2, ) return getattr(_get_context_value(), "outputs_list", []) @@ -188,6 +189,7 @@ def inputs_list(self): warnings.warn( "inputs_list is deprecated, use args_grouping instead", DeprecationWarning, + stacklevel=2, ) return getattr(_get_context_value(), "inputs_list", []) @@ -199,6 +201,7 @@ def states_list(self): warnings.warn( "states_list is deprecated, use args_grouping instead", DeprecationWarning, + stacklevel=2, ) return getattr(_get_context_value(), "states_list", []) diff --git a/dash/dash.py b/dash/dash.py index 122cf54dd6..5666dc0ce7 100644 --- a/dash/dash.py +++ b/dash/dash.py @@ -643,7 +643,8 @@ def __init__( # pylint: disable=too-many-statements if self.__class__.__name__ == "JupyterDash": warnings.warn( "JupyterDash is deprecated, use Dash instead.\n" - "See https://dash.plotly.com/dash-in-jupyter for more details." + "See https://dash.plotly.com/dash-in-jupyter for more details.", + stacklevel=2, ) self.setup_startup_routes() diff --git a/dash/development/_jl_components_generation.py b/dash/development/_jl_components_generation.py index 771ac0180a..4b7a7be4e1 100644 --- a/dash/development/_jl_components_generation.py +++ b/dash/development/_jl_components_generation.py @@ -468,7 +468,8 @@ def generate_class_string(name, props, description, project_shortname, prefix): ( 'WARNING: prop "{}" in component "{}" is a Julia keyword' " - REMOVED FROM THE JULIA COMPONENT" - ).format(item, name) + ).format(item, name), + stacklevel=2, ) default_paramtext += ", ".join(":{}".format(p) for p in prop_keys) diff --git a/dash/development/_r_components_generation.py b/dash/development/_r_components_generation.py index 18ac60d5d8..e392dc9aca 100644 --- a/dash/development/_r_components_generation.py +++ b/dash/development/_r_components_generation.py @@ -216,7 +216,8 @@ def generate_class_string(name, props, project_shortname, prefix): ( 'WARNING: prop "{}" in component "{}" is an R keyword' " - REMOVED FROM THE R COMPONENT" - ).format(item, name) + ).format(item, name), + stacklevel=2, ) default_argtext += ", ".join("{}=NULL".format(p) for p in prop_keys) diff --git a/dash/development/base_component.py b/dash/development/base_component.py index 02579ff2e2..0e93af5e3e 100644 --- a/dash/development/base_component.py +++ b/dash/development/base_component.py @@ -451,7 +451,7 @@ def _validate_deprecation(self): _ns = getattr(self, "_namespace", "") deprecation_message = _deprecated_components.get(_ns, {}).get(_type) if deprecation_message: - warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message))) + warnings.warn(DeprecationWarning(textwrap.dedent(deprecation_message)), stacklevel=2) ComponentSingleType = typing.Union[str, int, float, Component, None] diff --git a/dash/resources.py b/dash/resources.py index e197b6753e..62fddb24af 100644 --- a/dash/resources.py +++ b/dash/resources.py @@ -111,7 +111,8 @@ def _filter_resources( "or `app.css.append_css`, use `external_scripts` " "or `external_stylesheets` instead.\n" "See https://dash.plotly.com/external-resources" - ) + ), + stacklevel=2, ) continue else: diff --git a/dash/testing/browser.py b/dash/testing/browser.py index 8a82399a97..09af45c76d 100644 --- a/dash/testing/browser.py +++ b/dash/testing/browser.py @@ -624,7 +624,7 @@ def get_logs(self): for entry in self.driver.get_log("browser") if entry["timestamp"] > self._last_ts ] - warnings.warn("get_logs always return None with webdrivers other than Chrome") + warnings.warn("get_logs always return None with webdrivers other than Chrome", stacklevel=2) return None def reset_log_timestamp(self):