1111import logging
1212import shlex
1313import typing as t
14- import warnings
1514
1615from libtmux ._internal .query_list import QueryList
1716from libtmux .common import tmux_cmd
@@ -797,31 +796,10 @@ def split_window(
797796
798797 ``percent=25`` deprecated in favor of ``size="25%"``.
799798 """
800- warnings .warn (
801- "Window.split_window() is deprecated in favor of Window.split()" ,
802- category = DeprecationWarning ,
803- stacklevel = 2 ,
804- )
805-
806- if percent is not None :
807- # Deprecated in 3.1 in favor of -l
808- warnings .warn (
809- f'Deprecated in favor of size="{ str (percent ).rstrip ("%" )} %" '
810- '(using the "-l" flag).' ,
811- category = DeprecationWarning ,
812- stacklevel = 2 ,
813- )
814- if size is None :
815- size = f"{ str (percent ).rstrip ('%' )} %"
816-
817- return self .split (
818- target = target ,
819- start_directory = start_directory ,
820- attach = attach ,
821- direction = PaneDirection .Below if vertical else PaneDirection .Right ,
822- shell = shell ,
823- size = size ,
824- environment = environment ,
799+ raise exc .DeprecatedError (
800+ deprecated = "Window.split_window()" ,
801+ replacement = "Window.split()" ,
802+ version = "0.33.0" ,
825803 )
826804
827805 @property
@@ -834,15 +812,11 @@ def attached_pane(self) -> Pane | None:
834812
835813 Deprecated in favor of :meth:`.active_pane`.
836814 """
837- warnings . warn (
838- "Window.attached_pane() is deprecated in favor of Window.active_pane() " ,
839- category = DeprecationWarning ,
840- stacklevel = 2 ,
815+ raise exc . DeprecatedError (
816+ deprecated = "Window.attached_pane" ,
817+ replacement = "Window.active_pane" ,
818+ version = "0.31.0" ,
841819 )
842- panes = self .panes .filter (pane_active = "1" )
843- if len (panes ) > 0 :
844- return panes [0 ]
845- return None
846820
847821 def select_window (self ) -> Window :
848822 """Select window.
@@ -853,13 +827,11 @@ def select_window(self) -> Window:
853827
854828 Deprecated in favor of :meth:`.select()`.
855829 """
856- warnings . warn (
857- "Window.select_window() is deprecated in favor of Window.select ()" ,
858- category = DeprecationWarning ,
859- stacklevel = 2 ,
830+ raise exc . DeprecatedError (
831+ deprecated = "Window.select_window()" ,
832+ replacement = "Window.select()" ,
833+ version = "0.30.0" ,
860834 )
861- assert isinstance (self .window_index , str )
862- return self .session .select_window (self .window_index )
863835
864836 def kill_window (self ) -> None :
865837 """Kill the current :class:`Window` object. ``$ tmux kill-window``.
@@ -870,15 +842,11 @@ def kill_window(self) -> None:
870842
871843 Deprecated in favor of :meth:`.kill()`.
872844 """
873- warnings . warn (
874- "Window.kill_server() is deprecated in favor of Window.kill ()" ,
875- category = DeprecationWarning ,
876- stacklevel = 2 ,
845+ raise exc . DeprecatedError (
846+ deprecated = "Window.kill_window ()" ,
847+ replacement = "Window.kill()" ,
848+ version = "0.30.0" ,
877849 )
878- proc = self .cmd ("kill-window" )
879-
880- if proc .stderr :
881- raise exc .LibTmuxException (proc .stderr )
882850
883851 def set_window_option (
884852 self ,
@@ -892,12 +860,11 @@ def set_window_option(
892860 Deprecated by :meth:`Window.set_option()`.
893861
894862 """
895- warnings . warn (
896- "Window.set_window_option() is deprecated " ,
897- category = DeprecationWarning ,
898- stacklevel = 2 ,
863+ raise exc . DeprecatedError (
864+ deprecated = "Window.set_window_option()" ,
865+ replacement = "Window.set_option()" ,
866+ version = "0.26.0" ,
899867 )
900- return self .set_option (option = option , value = value )
901868
902869 def show_window_options (self , g : bool | None = False ) -> WindowOptionDict :
903870 """Show options for tmux window. Deprecated by :meth:`Window.show_options()`.
@@ -907,14 +874,10 @@ def show_window_options(self, g: bool | None = False) -> WindowOptionDict:
907874 Deprecated by :meth:`Window.show_options()`.
908875
909876 """
910- warnings .warn (
911- "Window.show_window_options() is deprecated" ,
912- category = DeprecationWarning ,
913- stacklevel = 2 ,
914- )
915- return self .show_options (
916- global_ = g or False ,
917- scope = OptionScope .Window ,
877+ raise exc .DeprecatedError (
878+ deprecated = "Window.show_window_options()" ,
879+ replacement = "Window.show_options()" ,
880+ version = "0.26.0" ,
918881 )
919882
920883 def show_window_option (
@@ -929,15 +892,10 @@ def show_window_option(
929892 Deprecated by :meth:`Window.show_option()`.
930893
931894 """
932- warnings .warn (
933- "Window.show_window_option() is deprecated" ,
934- category = DeprecationWarning ,
935- stacklevel = 2 ,
936- )
937- return self .show_option (
938- option = option ,
939- g = g ,
940- scope = OptionScope .Window ,
895+ raise exc .DeprecatedError (
896+ deprecated = "Window.show_window_option()" ,
897+ replacement = "Window.show_option()" ,
898+ version = "0.26.0" ,
941899 )
942900
943901 def get (self , key : str , default : t .Any | None = None ) -> t .Any :
@@ -949,12 +907,11 @@ def get(self, key: str, default: t.Any | None = None) -> t.Any:
949907 accessed via ``window.window_name``.
950908
951909 """
952- warnings . warn (
953- "Window.get() is deprecated " ,
954- category = DeprecationWarning ,
955- stacklevel = 2 ,
910+ raise exc . DeprecatedError (
911+ deprecated = "Window.get()" ,
912+ replacement = "direct attribute access (e.g., window.window_name)" ,
913+ version = "0.16.0" ,
956914 )
957- return getattr (self , key , default )
958915
959916 def __getitem__ (self , key : str ) -> t .Any :
960917 """Return item lookup by key. Deprecated in favor of attributes.
@@ -965,12 +922,11 @@ def __getitem__(self, key: str) -> t.Any:
965922 accessed via ``window.window_name``.
966923
967924 """
968- warnings . warn (
969- f"Item lookups, e.g. window[' { key } '] is deprecated " ,
970- category = DeprecationWarning ,
971- stacklevel = 2 ,
925+ raise exc . DeprecatedError (
926+ deprecated = "Window[ key] lookup " ,
927+ replacement = "direct attribute access (e.g., window.window_name)" ,
928+ version = "0.16.0" ,
972929 )
973- return getattr (self , key )
974930
975931 def get_by_id (self , pane_id : str ) -> Pane | None :
976932 """Return pane by id. Deprecated in favor of :meth:`.panes.get()`.
@@ -980,12 +936,11 @@ def get_by_id(self, pane_id: str) -> Pane | None:
980936 Deprecated by :meth:`.panes.get()`.
981937
982938 """
983- warnings . warn (
984- "Window.get_by_id() is deprecated " ,
985- category = DeprecationWarning ,
986- stacklevel = 2 ,
939+ raise exc . DeprecatedError (
940+ deprecated = "Window.get_by_id()" ,
941+ replacement = "Window.panes.get(pane_id=..., default=None)" ,
942+ version = "0.16.0" ,
987943 )
988- return self .panes .get (pane_id = pane_id , default = None )
989944
990945 def where (self , kwargs : dict [str , t .Any ]) -> list [Pane ]:
991946 """Filter through panes, return list of :class:`Pane`.
@@ -995,15 +950,11 @@ def where(self, kwargs: dict[str, t.Any]) -> list[Pane]:
995950 Deprecated by :meth:`.panes.filter()`.
996951
997952 """
998- warnings . warn (
999- "Window.where() is deprecated " ,
1000- category = DeprecationWarning ,
1001- stacklevel = 2 ,
953+ raise exc . DeprecatedError (
954+ deprecated = "Window.where()" ,
955+ replacement = "Window.panes.filter()" ,
956+ version = "0.16.0" ,
1002957 )
1003- try :
1004- return self .panes .filter (** kwargs )
1005- except IndexError :
1006- return []
1007958
1008959 def find_where (self , kwargs : dict [str , t .Any ]) -> Pane | None :
1009960 """Filter through panes, return first :class:`Pane`.
@@ -1013,12 +964,11 @@ def find_where(self, kwargs: dict[str, t.Any]) -> Pane | None:
1013964 Slated to be removed in favor of :meth:`.panes.get()`.
1014965
1015966 """
1016- warnings . warn (
1017- "Window.find_where() is deprecated " ,
1018- category = DeprecationWarning ,
1019- stacklevel = 2 ,
967+ raise exc . DeprecatedError (
968+ deprecated = "Window.find_where()" ,
969+ replacement = "Window.panes.get(default=None, **kwargs)" ,
970+ version = "0.16.0" ,
1020971 )
1021- return self .panes .get (default = None , ** kwargs )
1022972
1023973 def _list_panes (self ) -> list [PaneDict ]:
1024974 """Return list of panes (deprecated in favor of :meth:`.panes`).
@@ -1028,12 +978,11 @@ def _list_panes(self) -> list[PaneDict]:
1028978 Slated to be removed in favor of :attr:`.panes`.
1029979
1030980 """
1031- warnings . warn (
1032- "Window._list_panes() is deprecated " ,
1033- category = DeprecationWarning ,
1034- stacklevel = 2 ,
981+ raise exc . DeprecatedError (
982+ deprecated = "Window._list_panes()" ,
983+ replacement = "Window.panes property" ,
984+ version = "0.16.0" ,
1035985 )
1036- return [pane .__dict__ for pane in self .panes ]
1037986
1038987 @property
1039988 def _panes (self ) -> list [PaneDict ]:
@@ -1044,8 +993,11 @@ def _panes(self) -> list[PaneDict]:
1044993 Slated to be removed in favor of :attr:`.panes`.
1045994
1046995 """
1047- warnings .warn ("_panes is deprecated" , category = DeprecationWarning , stacklevel = 2 )
1048- return self ._list_panes ()
996+ raise exc .DeprecatedError (
997+ deprecated = "Window._panes" ,
998+ replacement = "Window.panes property" ,
999+ version = "0.16.0" ,
1000+ )
10491001
10501002 def list_panes (self ) -> list [Pane ]:
10511003 """Return list of :class:`Pane` for the window.
@@ -1055,12 +1007,11 @@ def list_panes(self) -> list[Pane]:
10551007 Slated to be removed in favor of :attr:`.panes`.
10561008
10571009 """
1058- warnings . warn (
1059- " list_panes() is deprecated " ,
1060- category = DeprecationWarning ,
1061- stacklevel = 2 ,
1010+ raise exc . DeprecatedError (
1011+ deprecated = "Window. list_panes()" ,
1012+ replacement = "Window.panes property" ,
1013+ version = "0.16.0" ,
10621014 )
1063- return self .panes
10641015
10651016 @property
10661017 def children (self ) -> QueryList [Pane ]:
@@ -1071,9 +1022,8 @@ def children(self) -> QueryList[Pane]:
10711022 Slated to be removed in favor of :attr:`.panes`.
10721023
10731024 """
1074- warnings . warn (
1075- "Window.children is deprecated " ,
1076- category = DeprecationWarning ,
1077- stacklevel = 2 ,
1025+ raise exc . DeprecatedError (
1026+ deprecated = "Window.children" ,
1027+ replacement = "Window.panes property" ,
1028+ version = "0.16.0" ,
10781029 )
1079- return self .panes
0 commit comments