Skip to content

Commit 11e7f7d

Browse files
committed
Pane(refactor): Replace deprecation warnings with DeprecatedError
why: Enforce immediate migration from deprecated APIs. what: - select_pane() raises DeprecatedError, use select() instead - split_window() raises DeprecatedError, use split() instead - resize_pane() raises DeprecatedError, use resize() instead - get(), __getitem__() raise DeprecatedError, use attribute access - set_width()/set_height() updated to use resize() internally
1 parent aa97954 commit 11e7f7d

File tree

1 file changed

+22
-50
lines changed

1 file changed

+22
-50
lines changed

src/libtmux/pane.py

Lines changed: 22 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import logging
1212
import pathlib
1313
import typing as t
14-
import warnings
1514

1615
from libtmux import exc
1716
from libtmux.common import tmux_cmd
@@ -544,16 +543,11 @@ def select_pane(self) -> Pane:
544543
545544
Deprecated in favor of :meth:`.select()`.
546545
"""
547-
warnings.warn(
548-
"Pane.select_pane() is deprecated in favor of Pane.select()",
549-
category=DeprecationWarning,
550-
stacklevel=2,
546+
raise exc.DeprecatedError(
547+
deprecated="Pane.select_pane()",
548+
replacement="Pane.select()",
549+
version="0.30.0",
551550
)
552-
assert isinstance(self.pane_id, str)
553-
pane = self.window.select_pane(self.pane_id)
554-
if pane is None:
555-
raise exc.PaneNotFound(pane_id=self.pane_id)
556-
return pane
557551

558552
def split(
559553
self,
@@ -716,7 +710,7 @@ def set_width(self, width: int) -> Pane:
716710
width : int
717711
pane width, in cells
718712
"""
719-
self.resize_pane(width=width)
713+
self.resize(width=width)
720714
return self
721715

722716
def set_height(self, height: int) -> Pane:
@@ -727,7 +721,7 @@ def set_height(self, height: int) -> Pane:
727721
height : int
728722
height of pain, in cells
729723
"""
730-
self.resize_pane(height=height)
724+
self.resize(height=height)
731725
return self
732726

733727
def enter(self) -> Pane:
@@ -895,21 +889,10 @@ def split_window(
895889
896890
Deprecated in favor of :meth:`.split`.
897891
"""
898-
warnings.warn(
899-
"Pane.split_window() is deprecated in favor of Pane.split()",
900-
category=DeprecationWarning,
901-
stacklevel=2,
902-
)
903-
if size is None and percent is not None:
904-
size = f"{str(percent).rstrip('%')}%"
905-
return self.split(
906-
target=target,
907-
attach=attach,
908-
start_directory=start_directory,
909-
direction=PaneDirection.Below if vertical else PaneDirection.Right,
910-
shell=shell,
911-
size=size,
912-
environment=environment,
892+
raise exc.DeprecatedError(
893+
deprecated="Pane.split_window()",
894+
replacement="Pane.split()",
895+
version="0.33.0",
913896
)
914897

915898
def get(self, key: str, default: t.Any | None = None) -> t.Any:
@@ -921,12 +904,11 @@ def get(self, key: str, default: t.Any | None = None) -> t.Any:
921904
accessed via ``pane.window_name``.
922905
923906
"""
924-
warnings.warn(
925-
"Pane.get() is deprecated",
926-
category=DeprecationWarning,
927-
stacklevel=2,
907+
raise exc.DeprecatedError(
908+
deprecated="Pane.get()",
909+
replacement="direct attribute access (e.g., pane.pane_id)",
910+
version="0.16.0",
928911
)
929-
return getattr(self, key, default)
930912

931913
def __getitem__(self, key: str) -> t.Any:
932914
"""Return item lookup by key. Deprecated in favor of attributes.
@@ -937,12 +919,11 @@ def __getitem__(self, key: str) -> t.Any:
937919
accessed via ``pane.window_name``.
938920
939921
"""
940-
warnings.warn(
941-
f"Item lookups, e.g. pane['{key}'] is deprecated",
942-
category=DeprecationWarning,
943-
stacklevel=2,
922+
raise exc.DeprecatedError(
923+
deprecated="Pane[key] lookup",
924+
replacement="direct attribute access (e.g., pane.pane_id)",
925+
version="0.16.0",
944926
)
945-
return getattr(self, key)
946927

947928
def resize_pane(
948929
self,
@@ -965,17 +946,8 @@ def resize_pane(
965946
966947
Deprecated by :meth:`Pane.resize`.
967948
"""
968-
warnings.warn(
969-
"Deprecated: Use Pane.resize() instead of Pane.resize_pane()",
970-
category=DeprecationWarning,
971-
stacklevel=2,
972-
)
973-
return self.resize(
974-
adjustment_direction=adjustment_direction,
975-
adjustment=adjustment,
976-
height=height,
977-
width=width,
978-
zoom=zoom,
979-
mouse=mouse,
980-
trim_below=trim_below,
949+
raise exc.DeprecatedError(
950+
deprecated="Pane.resize_pane()",
951+
replacement="Pane.resize()",
952+
version="0.28.0",
981953
)

0 commit comments

Comments
 (0)