From dd464cdf4d0c91cbb936207be9c84bc363ad61bc Mon Sep 17 00:00:00 2001 From: Aran-Fey Date: Fri, 13 Sep 2024 12:27:58 +0200 Subject: [PATCH] fix stacklevel of deprecation warnings --- rio/components/component.py | 9 ++++++--- rio/deprecations.py | 3 +++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/rio/components/component.py b/rio/components/component.py index 783dd455..849fc79d 100644 --- a/rio/components/component.py +++ b/rio/components/component.py @@ -335,9 +335,6 @@ class Component(abc.ABC, metaclass=ComponentMeta): width: float | Literal["grow", "natural"] | None = kwargs.pop( "width", None ) - height: float | Literal["grow", "natural"] | None = kwargs.pop( - "height", None - ) if width is None: pass @@ -345,6 +342,7 @@ class Component(abc.ABC, metaclass=ComponentMeta): deprecations.warn( since="0.9.3", message="The `width` attribute of `rio.Component` is deprecated. Please use `min_width` and `grow_x` instead.", + stacklevel=6, ) if width == "natural": @@ -354,12 +352,17 @@ class Component(abc.ABC, metaclass=ComponentMeta): else: kwargs["min_width"] = width + height: float | Literal["grow", "natural"] | None = kwargs.pop( + "height", None + ) + if height is None: pass else: deprecations.warn( since="0.9.3", message="The `height` attribute of `rio.Component` is deprecated. Please use `min_height` and `grow_y` instead.", + stacklevel=6, ) if height == "natural": diff --git a/rio/deprecations.py b/rio/deprecations.py index 6f8d135f..b6039d92 100644 --- a/rio/deprecations.py +++ b/rio/deprecations.py @@ -27,10 +27,12 @@ def warn( *, since: str, message: str, + stacklevel: int = 1, ) -> None: warnings.warn( f"Deprecated since version {since}: {message}", RioDeprecationWarning, + stacklevel=stacklevel, ) @@ -96,6 +98,7 @@ def component_kwarg_renamed( warn( since=since, message=f"The `{old_name}` parameter of `rio.{component_class.__name__}` is deprecated. Please use `{new_name}` instead.", + stacklevel=6, ) # Delegate to the original _remap_constructor_arguments method