1111import logging
1212import pathlib
1313import typing as t
14- import warnings
1514
1615from libtmux ._internal .query_list import QueryList
1716from libtmux .common import tmux_cmd
@@ -644,12 +643,11 @@ def attached_pane(self) -> Pane | None:
644643
645644 Deprecated in favor of :meth:`.active_pane`.
646645 """
647- warnings . warn (
648- "Session.attached_pane() is deprecated in favor of Session.active_pane() " ,
649- category = DeprecationWarning ,
650- stacklevel = 2 ,
646+ raise exc . DeprecatedError (
647+ deprecated = "Session.attached_pane" ,
648+ replacement = "Session.active_pane" ,
649+ version = "0.31.0" ,
651650 )
652- return self .active_window .active_pane
653651
654652 @property
655653 def attached_window (self ) -> Window :
@@ -661,13 +659,11 @@ def attached_window(self) -> Window:
661659
662660 Deprecated in favor of :meth:`.active_window`.
663661 """
664- warnings .warn (
665- "Session.attached_window() is deprecated in favor of "
666- "Session.active_window()" ,
667- category = DeprecationWarning ,
668- stacklevel = 2 ,
662+ raise exc .DeprecatedError (
663+ deprecated = "Session.attached_window" ,
664+ replacement = "Session.active_window" ,
665+ version = "0.31.0" ,
669666 )
670- return self .active_window
671667
672668 def attach_session (self ) -> Session :
673669 """Return ``$ tmux attach-session`` aka alias: ``$ tmux attach``.
@@ -678,17 +674,11 @@ def attach_session(self) -> Session:
678674
679675 Deprecated in favor of :meth:`.attach()`.
680676 """
681- warnings . warn (
682- "Session.attach_session() is deprecated in favor of Session.attach ()" ,
683- category = DeprecationWarning ,
684- stacklevel = 2 ,
677+ raise exc . DeprecatedError (
678+ deprecated = "Session.attach_session()" ,
679+ replacement = "Session.attach()" ,
680+ version = "0.30.0" ,
685681 )
686- proc = self .cmd ("attach-session" )
687-
688- if proc .stderr :
689- raise exc .LibTmuxException (proc .stderr )
690-
691- return self
692682
693683 def kill_session (self ) -> None :
694684 """Destroy session.
@@ -699,15 +689,11 @@ def kill_session(self) -> None:
699689
700690 Deprecated in favor of :meth:`.kill()`.
701691 """
702- warnings . warn (
703- "Session.kill_session() is deprecated in favor of Session.kill ()" ,
704- category = DeprecationWarning ,
705- stacklevel = 2 ,
692+ raise exc . DeprecatedError (
693+ deprecated = "Session.kill_session()" ,
694+ replacement = "Session.kill()" ,
695+ version = "0.30.0" ,
706696 )
707- proc = self .cmd ("kill-session" )
708-
709- if proc .stderr :
710- raise exc .LibTmuxException (proc .stderr )
711697
712698 def get (self , key : str , default : t .Any | None = None ) -> t .Any :
713699 """Return key-based lookup. Deprecated by attributes.
@@ -718,12 +704,11 @@ def get(self, key: str, default: t.Any | None = None) -> t.Any:
718704 accessed via ``session.session_name``.
719705
720706 """
721- warnings . warn (
722- "Session.get() is deprecated " ,
723- category = DeprecationWarning ,
724- stacklevel = 2 ,
707+ raise exc . DeprecatedError (
708+ deprecated = "Session.get()" ,
709+ replacement = "direct attribute access (e.g., session.session_name)" ,
710+ version = "0.16.0" ,
725711 )
726- return getattr (self , key , default )
727712
728713 def __getitem__ (self , key : str ) -> t .Any :
729714 """Return item lookup by key. Deprecated in favor of attributes.
@@ -734,12 +719,11 @@ def __getitem__(self, key: str) -> t.Any:
734719 accessed via ``session.session_name``.
735720
736721 """
737- warnings . warn (
738- f"Item lookups, e.g. session[' { key } '] is deprecated " ,
739- category = DeprecationWarning ,
740- stacklevel = 2 ,
722+ raise exc . DeprecatedError (
723+ deprecated = "Session[ key] lookup " ,
724+ replacement = "direct attribute access (e.g., session.session_name)" ,
725+ version = "0.16.0" ,
741726 )
742- return getattr (self , key )
743727
744728 def get_by_id (self , session_id : str ) -> Window | None :
745729 """Return window by id. Deprecated in favor of :meth:`.windows.get()`.
@@ -749,12 +733,11 @@ def get_by_id(self, session_id: str) -> Window | None:
749733 Deprecated by :meth:`.windows.get()`.
750734
751735 """
752- warnings . warn (
753- "Session.get_by_id() is deprecated " ,
754- category = DeprecationWarning ,
755- stacklevel = 2 ,
736+ raise exc . DeprecatedError (
737+ deprecated = "Session.get_by_id()" ,
738+ replacement = "Session.windows.get(window_id=..., default=None)" ,
739+ version = "0.16.0" ,
756740 )
757- return self .windows .get (window_id = session_id , default = None )
758741
759742 def where (self , kwargs : dict [str , t .Any ]) -> list [Window ]:
760743 """Filter through windows, return list of :class:`Window`.
@@ -764,15 +747,11 @@ def where(self, kwargs: dict[str, t.Any]) -> list[Window]:
764747 Deprecated by :meth:`.windows.filter()`.
765748
766749 """
767- warnings . warn (
768- "Session.where() is deprecated " ,
769- category = DeprecationWarning ,
770- stacklevel = 2 ,
750+ raise exc . DeprecatedError (
751+ deprecated = "Session.where()" ,
752+ replacement = "Session.windows.filter()" ,
753+ version = "0.16.0" ,
771754 )
772- try :
773- return self .windows .filter (** kwargs )
774- except IndexError :
775- return []
776755
777756 def find_where (self , kwargs : dict [str , t .Any ]) -> Window | None :
778757 """Filter through windows, return first :class:`Window`.
@@ -782,12 +761,11 @@ def find_where(self, kwargs: dict[str, t.Any]) -> Window | None:
782761 Slated to be removed in favor of :meth:`.windows.get()`.
783762
784763 """
785- warnings . warn (
786- "Session.find_where() is deprecated " ,
787- category = DeprecationWarning ,
788- stacklevel = 2 ,
764+ raise exc . DeprecatedError (
765+ deprecated = "Session.find_where()" ,
766+ replacement = "Session.windows.get(default=None, **kwargs)" ,
767+ version = "0.16.0" ,
789768 )
790- return self .windows .get (default = None , ** kwargs )
791769
792770 def _list_windows (self ) -> list [WindowDict ]:
793771 """Return list of windows (deprecated in favor of :attr:`.windows`).
@@ -797,12 +775,11 @@ def _list_windows(self) -> list[WindowDict]:
797775 Slated to be removed in favor of :attr:`.windows`.
798776
799777 """
800- warnings . warn (
801- "Session._list_windows() is deprecated " ,
802- category = DeprecationWarning ,
803- stacklevel = 2 ,
778+ raise exc . DeprecatedError (
779+ deprecated = "Session._list_windows()" ,
780+ replacement = "Session.windows property" ,
781+ version = "0.16.0" ,
804782 )
805- return [w .__dict__ for w in self .windows ]
806783
807784 @property
808785 def _windows (self ) -> list [WindowDict ]:
@@ -813,12 +790,11 @@ def _windows(self) -> list[WindowDict]:
813790 Slated to be removed in favor of :attr:`.windows`.
814791
815792 """
816- warnings . warn (
817- "Session._windows is deprecated " ,
818- category = DeprecationWarning ,
819- stacklevel = 2 ,
793+ raise exc . DeprecatedError (
794+ deprecated = "Session._windows" ,
795+ replacement = "Session.windows property" ,
796+ version = "0.16.0" ,
820797 )
821- return self ._list_windows ()
822798
823799 def list_windows (self ) -> list [Window ]:
824800 """Return a list of :class:`Window` from the ``tmux(1)`` session.
@@ -828,12 +804,11 @@ def list_windows(self) -> list[Window]:
828804 Slated to be removed in favor of :attr:`.windows`.
829805
830806 """
831- warnings . warn (
832- "Session.list_windows() is deprecated " ,
833- category = DeprecationWarning ,
834- stacklevel = 2 ,
807+ raise exc . DeprecatedError (
808+ deprecated = "Session.list_windows()" ,
809+ replacement = "Session.windows property" ,
810+ version = "0.16.0" ,
835811 )
836- return self .windows
837812
838813 @property
839814 def children (self ) -> QueryList [Window ]:
@@ -844,9 +819,8 @@ def children(self) -> QueryList[Window]:
844819 Slated to be removed in favor of :attr:`.windows`.
845820
846821 """
847- warnings . warn (
848- "Session.children is deprecated " ,
849- category = DeprecationWarning ,
850- stacklevel = 2 ,
822+ raise exc . DeprecatedError (
823+ deprecated = "Session.children" ,
824+ replacement = "Session.windows property" ,
825+ version = "0.16.0" ,
851826 )
852- return self .windows
0 commit comments