fix stacklevel of deprecation warnings

This commit is contained in:
Aran-Fey
2024-09-13 12:27:58 +02:00
parent 4f60963129
commit dd464cdf4d
2 changed files with 9 additions and 3 deletions

View File

@@ -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":

View File

@@ -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