Skip to content

Commit d9abc45

Browse files
committed
fix(API): Use DeprecationWarning for APIs being deprecated
1 parent 16ac4a6 commit d9abc45

File tree

4 files changed

+126
-31
lines changed

4 files changed

+126
-31
lines changed

src/libtmux/pane.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,9 @@ def get(self, key: str, default: t.Optional[t.Any] = None) -> t.Any:
521521
accessed via ``pane.window_name``.
522522
523523
"""
524-
warnings.warn("Pane.get() is deprecated", stacklevel=2)
524+
warnings.warn(
525+
"Pane.get() is deprecated", category=DeprecationWarning, stacklevel=2
526+
)
525527
return getattr(self, key, default)
526528

527529
def __getitem__(self, key: str) -> t.Any:
@@ -533,7 +535,11 @@ def __getitem__(self, key: str) -> t.Any:
533535
accessed via ``pane.window_name``.
534536
535537
"""
536-
warnings.warn(f"Item lookups, e.g. pane['{key}'] is deprecated", stacklevel=2)
538+
warnings.warn(
539+
f"Item lookups, e.g. pane['{key}'] is deprecated",
540+
category=DeprecationWarning,
541+
stacklevel=2,
542+
)
537543
return getattr(self, key)
538544

539545
def resize_pane(
@@ -559,6 +565,7 @@ def resize_pane(
559565
"""
560566
warnings.warn(
561567
"Deprecated: Use Pane.resize() instead of Pane.resize_pane()",
568+
category=DeprecationWarning,
562569
stacklevel=2,
563570
)
564571
return self.resize(

src/libtmux/server.py

Lines changed: 51 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,11 @@ def _list_panes(self) -> t.List[PaneDict]:
588588
Deprecated in favor of :attr:`.panes`.
589589
590590
"""
591-
warnings.warn("Server._list_panes() is deprecated", stacklevel=2)
591+
warnings.warn(
592+
"Server._list_panes() is deprecated",
593+
category=DeprecationWarning,
594+
stacklevel=2,
595+
)
592596
return [p.__dict__ for p in self.panes]
593597

594598
def _update_panes(self) -> "Server":
@@ -602,7 +606,11 @@ def _update_panes(self) -> "Server":
602606
-------
603607
:class:`Server`
604608
"""
605-
warnings.warn("Server._update_panes() is deprecated", stacklevel=2)
609+
warnings.warn(
610+
"Server._update_panes() is deprecated",
611+
category=DeprecationWarning,
612+
stacklevel=2,
613+
)
606614
self._list_panes()
607615
return self
608616

@@ -614,7 +622,11 @@ def get_by_id(self, session_id: str) -> t.Optional[Session]:
614622
Deprecated by :meth:`.sessions.get()`.
615623
616624
"""
617-
warnings.warn("Server.get_by_id() is deprecated", stacklevel=2)
625+
warnings.warn(
626+
"Server.get_by_id() is deprecated",
627+
category=DeprecationWarning,
628+
stacklevel=2,
629+
)
618630
return self.sessions.get(session_id=session_id, default=None)
619631

620632
def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Session]:
@@ -625,7 +637,11 @@ def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Session]:
625637
Deprecated by :meth:`.session.filter()`.
626638
627639
"""
628-
warnings.warn("Server.find_where() is deprecated", stacklevel=2)
640+
warnings.warn(
641+
"Server.find_where() is deprecated",
642+
category=DeprecationWarning,
643+
stacklevel=2,
644+
)
629645
try:
630646
return self.sessions.filter(**kwargs)
631647
except IndexError:
@@ -639,7 +655,11 @@ def find_where(self, kwargs: t.Dict[str, t.Any]) -> t.Optional[Session]:
639655
Slated to be removed in favor of :meth:`.sessions.get()`.
640656
641657
"""
642-
warnings.warn("Server.find_where() is deprecated", stacklevel=2)
658+
warnings.warn(
659+
"Server.find_where() is deprecated",
660+
category=DeprecationWarning,
661+
stacklevel=2,
662+
)
643663
return self.sessions.get(default=None, **kwargs)
644664

645665
def _list_windows(self) -> t.List[WindowDict]:
@@ -655,7 +675,11 @@ def _list_windows(self) -> t.List[WindowDict]:
655675
Slated to be removed in favor of :attr:`.windows`.
656676
657677
"""
658-
warnings.warn("Server._list_windows() is deprecated", stacklevel=2)
678+
warnings.warn(
679+
"Server._list_windows() is deprecated",
680+
category=DeprecationWarning,
681+
stacklevel=2,
682+
)
659683
return [w.__dict__ for w in self.windows]
660684

661685
def _update_windows(self) -> "Server":
@@ -666,7 +690,11 @@ def _update_windows(self) -> "Server":
666690
Deprecated in favor of :attr:`.windows` and returning ``self``.
667691
668692
"""
669-
warnings.warn("Server._update_windows() is deprecated", stacklevel=2)
693+
warnings.warn(
694+
"Server._update_windows() is deprecated",
695+
category=DeprecationWarning,
696+
stacklevel=2,
697+
)
670698
self._list_windows()
671699
return self
672700

@@ -679,7 +707,9 @@ def _sessions(self) -> t.List[SessionDict]:
679707
Slated to be removed in favor of :attr:`.sessions`.
680708
681709
"""
682-
warnings.warn("Server._sessions is deprecated", stacklevel=2)
710+
warnings.warn(
711+
"Server._sessions is deprecated", category=DeprecationWarning, stacklevel=2
712+
)
683713
return self._list_sessions()
684714

685715
def _list_sessions(self) -> t.List["SessionDict"]:
@@ -689,7 +719,11 @@ def _list_sessions(self) -> t.List["SessionDict"]:
689719
690720
Slated to be removed in favor of :attr:`.sessions`.
691721
"""
692-
warnings.warn("Server._list_sessions() is deprecated", stacklevel=2)
722+
warnings.warn(
723+
"Server._list_sessions() is deprecated",
724+
category=DeprecationWarning,
725+
stacklevel=2,
726+
)
693727
return [s.__dict__ for s in self.sessions]
694728

695729
def list_sessions(self) -> t.List[Session]:
@@ -703,7 +737,11 @@ def list_sessions(self) -> t.List[Session]:
703737
-------
704738
list of :class:`Session`
705739
"""
706-
warnings.warn("Server.list_sessions is deprecated", stacklevel=2)
740+
warnings.warn(
741+
"Server.list_sessions is deprecated",
742+
category=DeprecationWarning,
743+
stacklevel=2,
744+
)
707745
return self.sessions
708746

709747
@property
@@ -715,5 +753,7 @@ def children(self) -> QueryList["Session"]:
715753
Slated to be removed in favor of :attr:`.sessions`.
716754
717755
"""
718-
warnings.warn("Server.children is deprecated", stacklevel=2)
756+
warnings.warn(
757+
"Server.children is deprecated", category=DeprecationWarning, stacklevel=2
758+
)
719759
return self.sessions

src/libtmux/session.py

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,9 @@ def get(self, key: str, default: t.Optional[t.Any] = None) -> t.Any:
604604
accessed via ``session.session_name``.
605605
606606
"""
607-
warnings.warn("Session.get() is deprecated", stacklevel=2)
607+
warnings.warn(
608+
"Session.get() is deprecated", category=DeprecationWarning, stacklevel=2
609+
)
608610
return getattr(self, key, default)
609611

610612
def __getitem__(self, key: str) -> t.Any:
@@ -618,6 +620,7 @@ def __getitem__(self, key: str) -> t.Any:
618620
"""
619621
warnings.warn(
620622
f"Item lookups, e.g. session['{key}'] is deprecated",
623+
category=DeprecationWarning,
621624
stacklevel=2,
622625
)
623626
return getattr(self, key)
@@ -630,7 +633,11 @@ def get_by_id(self, session_id: str) -> t.Optional[Window]:
630633
Deprecated by :meth:`.windows.get()`.
631634
632635
"""
633-
warnings.warn("Session.get_by_id() is deprecated", stacklevel=2)
636+
warnings.warn(
637+
"Session.get_by_id() is deprecated",
638+
category=DeprecationWarning,
639+
stacklevel=2,
640+
)
634641
return self.windows.get(window_id=session_id, default=None)
635642

636643
def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Window]:
@@ -641,7 +648,9 @@ def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Window]:
641648
Deprecated by :meth:`.windows.filter()`.
642649
643650
"""
644-
warnings.warn("Session.where() is deprecated", stacklevel=2)
651+
warnings.warn(
652+
"Session.where() is deprecated", category=DeprecationWarning, stacklevel=2
653+
)
645654
try:
646655
return self.windows.filter(**kwargs)
647656
except IndexError:
@@ -655,7 +664,11 @@ def find_where(self, kwargs: t.Dict[str, t.Any]) -> t.Optional[Window]:
655664
Slated to be removed in favor of :meth:`.windows.get()`.
656665
657666
"""
658-
warnings.warn("Session.find_where() is deprecated", stacklevel=2)
667+
warnings.warn(
668+
"Session.find_where() is deprecated",
669+
category=DeprecationWarning,
670+
stacklevel=2,
671+
)
659672
return self.windows.get(default=None, **kwargs)
660673

661674
def _list_windows(self) -> t.List["WindowDict"]:
@@ -666,7 +679,11 @@ def _list_windows(self) -> t.List["WindowDict"]:
666679
Slated to be removed in favor of :attr:`.windows`.
667680
668681
"""
669-
warnings.warn("Session._list_windows() is deprecated", stacklevel=2)
682+
warnings.warn(
683+
"Session._list_windows() is deprecated",
684+
category=DeprecationWarning,
685+
stacklevel=2,
686+
)
670687
return [w.__dict__ for w in self.windows]
671688

672689
@property
@@ -678,7 +695,9 @@ def _windows(self) -> t.List["WindowDict"]:
678695
Slated to be removed in favor of :attr:`.windows`.
679696
680697
"""
681-
warnings.warn("Session._windows is deprecated", stacklevel=2)
698+
warnings.warn(
699+
"Session._windows is deprecated", category=DeprecationWarning, stacklevel=2
700+
)
682701
return self._list_windows()
683702

684703
def list_windows(self) -> t.List["Window"]:
@@ -689,7 +708,11 @@ def list_windows(self) -> t.List["Window"]:
689708
Slated to be removed in favor of :attr:`.windows`.
690709
691710
"""
692-
warnings.warn("Session.list_windows() is deprecated", stacklevel=2)
711+
warnings.warn(
712+
"Session.list_windows() is deprecated",
713+
category=DeprecationWarning,
714+
stacklevel=2,
715+
)
693716
return self.windows
694717

695718
@property
@@ -701,5 +724,7 @@ def children(self) -> QueryList["Window"]:
701724
Slated to be removed in favor of :attr:`.windows`.
702725
703726
"""
704-
warnings.warn("Session.children is deprecated", stacklevel=2)
727+
warnings.warn(
728+
"Session.children is deprecated", category=DeprecationWarning, stacklevel=2
729+
)
705730
return self.windows

src/libtmux/window.py

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,6 @@ def split_window(
250250

251251
if percent is not None:
252252
tmux_args += ("-p %d" % percent,)
253-
254253
tmux_args += ("-P", "-F%s" % "".join(tmux_formats)) # output
255254

256255
if start_directory is not None:
@@ -731,7 +730,9 @@ def get(self, key: str, default: t.Optional[t.Any] = None) -> t.Any:
731730
accessed via ``window.window_name``.
732731
733732
"""
734-
warnings.warn("Window.get() is deprecated", stacklevel=2)
733+
warnings.warn(
734+
"Window.get() is deprecated", category=DeprecationWarning, stacklevel=2
735+
)
735736
return getattr(self, key, default)
736737

737738
def __getitem__(self, key: str) -> t.Any:
@@ -743,7 +744,11 @@ def __getitem__(self, key: str) -> t.Any:
743744
accessed via ``window.window_name``.
744745
745746
"""
746-
warnings.warn(f"Item lookups, e.g. window['{key}'] is deprecated", stacklevel=2)
747+
warnings.warn(
748+
f"Item lookups, e.g. window['{key}'] is deprecated",
749+
category=DeprecationWarning,
750+
stacklevel=2,
751+
)
747752
return getattr(self, key)
748753

749754
def get_by_id(self, pane_id: str) -> t.Optional[Pane]:
@@ -754,7 +759,11 @@ def get_by_id(self, pane_id: str) -> t.Optional[Pane]:
754759
Deprecated by :meth:`.panes.get()`.
755760
756761
"""
757-
warnings.warn("Window.get_by_id() is deprecated", stacklevel=2)
762+
warnings.warn(
763+
"Window.get_by_id() is deprecated",
764+
category=DeprecationWarning,
765+
stacklevel=2,
766+
)
758767
return self.panes.get(pane_id=pane_id, default=None)
759768

760769
def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Pane]:
@@ -765,7 +774,9 @@ def where(self, kwargs: t.Dict[str, t.Any]) -> t.List[Pane]:
765774
Deprecated by :meth:`.panes.filter()`.
766775
767776
"""
768-
warnings.warn("Window.where() is deprecated", stacklevel=2)
777+
warnings.warn(
778+
"Window.where() is deprecated", category=DeprecationWarning, stacklevel=2
779+
)
769780
try:
770781
return self.panes.filter(**kwargs)
771782
except IndexError:
@@ -779,7 +790,11 @@ def find_where(self, kwargs: t.Dict[str, t.Any]) -> t.Optional[Pane]:
779790
Slated to be removed in favor of :meth:`.panes.get()`.
780791
781792
"""
782-
warnings.warn("Window.find_where() is deprecated", stacklevel=2)
793+
warnings.warn(
794+
"Window.find_where() is deprecated",
795+
category=DeprecationWarning,
796+
stacklevel=2,
797+
)
783798
return self.panes.get(default=None, **kwargs)
784799

785800
def _list_panes(self) -> t.List[PaneDict]:
@@ -790,7 +805,11 @@ def _list_panes(self) -> t.List[PaneDict]:
790805
Slated to be removed in favor of :attr:`.panes`.
791806
792807
"""
793-
warnings.warn("Window._list_panes() is deprecated", stacklevel=2)
808+
warnings.warn(
809+
"Window._list_panes() is deprecated",
810+
category=DeprecationWarning,
811+
stacklevel=2,
812+
)
794813
return [pane.__dict__ for pane in self.panes]
795814

796815
@property
@@ -802,7 +821,7 @@ def _panes(self) -> t.List[PaneDict]:
802821
Slated to be removed in favor of :attr:`.panes`.
803822
804823
"""
805-
warnings.warn("_panes is deprecated", stacklevel=2)
824+
warnings.warn("_panes is deprecated", category=DeprecationWarning, stacklevel=2)
806825
return self._list_panes()
807826

808827
def list_panes(self) -> t.List["Pane"]:
@@ -813,7 +832,9 @@ def list_panes(self) -> t.List["Pane"]:
813832
Slated to be removed in favor of :attr:`.panes`.
814833
815834
"""
816-
warnings.warn("list_panes() is deprecated", stacklevel=2)
835+
warnings.warn(
836+
"list_panes() is deprecated", category=DeprecationWarning, stacklevel=2
837+
)
817838
return self.panes
818839

819840
@property
@@ -825,5 +846,7 @@ def children(self) -> QueryList["Pane"]:
825846
Slated to be removed in favor of :attr:`.panes`.
826847
827848
"""
828-
warnings.warn("Server.children is deprecated", stacklevel=2)
849+
warnings.warn(
850+
"Server.children is deprecated", category=DeprecationWarning, stacklevel=2
851+
)
829852
return self.panes

0 commit comments

Comments
 (0)