@@ -81,9 +81,10 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> None:
81
81
NotImplementedError
82
82
This method cannot be used on a snapshot.
83
83
"""
84
- raise NotImplementedError (
85
- "Cannot execute commands on a snapshot. Use a real Pane object instead." ,
84
+ error_msg = (
85
+ "Cannot execute commands on a snapshot. Use a real Pane object instead."
86
86
)
87
+ raise NotImplementedError (error_msg )
87
88
88
89
@property
89
90
def content (self ) -> list [str ] | None :
@@ -92,8 +93,8 @@ def content(self) -> list[str] | None:
92
93
Returns
93
94
-------
94
95
list[str] | None
95
- List of strings representing the content of the pane,
96
- or None if no content was captured.
96
+ List of strings representing the content of the pane, or None if no
97
+ content was captured.
97
98
"""
98
99
return self .pane_content
99
100
@@ -112,12 +113,13 @@ def capture_pane(
112
113
Returns
113
114
-------
114
115
list[str]
115
- List of strings representing the content of the pane, or empty list if no content
116
- was captured
116
+ List of strings representing the content of the pane, or empty list if
117
+ no content was captured
117
118
118
119
Notes
119
120
-----
120
- This method is overridden to return the cached content instead of executing tmux commands.
121
+ This method is overridden to return the cached content instead of executing
122
+ tmux commands.
121
123
"""
122
124
if self .pane_content is None :
123
125
return []
@@ -218,10 +220,11 @@ def from_pane(
218
220
219
221
# If all else fails, raise an error
220
222
if source_server is None :
221
- raise ValueError (
223
+ error_msg = (
222
224
"Cannot create snapshot: pane has no server attribute "
223
225
"and no window_snapshot provided"
224
226
)
227
+ raise ValueError (error_msg )
225
228
226
229
# Create a new instance
227
230
snapshot = cls .__new__ (cls )
@@ -275,9 +278,10 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> None:
275
278
NotImplementedError
276
279
This method cannot be used on a snapshot.
277
280
"""
278
- raise NotImplementedError (
279
- "Cannot execute commands on a snapshot. Use a real Window object instead." ,
281
+ error_msg = (
282
+ "Cannot execute commands on a snapshot. Use a real Window object instead."
280
283
)
284
+ raise NotImplementedError (error_msg )
281
285
282
286
@property
283
287
def panes (self ) -> QueryList [PaneSnapshot ]:
@@ -357,10 +361,11 @@ def from_window(
357
361
358
362
# If all else fails, raise an error
359
363
if source_server is None :
360
- raise ValueError (
364
+ error_msg = (
361
365
"Cannot create snapshot: window has no server attribute "
362
366
"and no session_snapshot provided"
363
367
)
368
+ raise ValueError (error_msg )
364
369
365
370
# Create a new instance
366
371
snapshot = cls .__new__ (cls )
@@ -426,9 +431,10 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> None:
426
431
NotImplementedError
427
432
This method cannot be used on a snapshot.
428
433
"""
429
- raise NotImplementedError (
430
- "Cannot execute commands on a snapshot. Use a real Session object instead." ,
434
+ error_msg = (
435
+ "Cannot execute commands on a snapshot. Use a real Session object instead."
431
436
)
437
+ raise NotImplementedError (error_msg )
432
438
433
439
@property
434
440
def windows (self ) -> QueryList [WindowSnapshot ]:
@@ -502,10 +508,11 @@ def from_session(
502
508
503
509
# If all else fails, raise an error
504
510
if source_server is None :
505
- raise ValueError (
511
+ error_msg = (
506
512
"Cannot create snapshot: session has no server attribute "
507
513
"and no server_snapshot provided"
508
514
)
515
+ raise ValueError (error_msg )
509
516
510
517
# Create a new instance
511
518
snapshot = cls .__new__ (cls )
@@ -579,9 +586,10 @@ def cmd(self, cmd: str, *args: t.Any, **kwargs: t.Any) -> None:
579
586
NotImplementedError
580
587
This method cannot be used on a snapshot.
581
588
"""
582
- raise NotImplementedError (
583
- "Cannot execute commands on a snapshot. Use a real Server object instead." ,
589
+ error_msg = (
590
+ "Cannot execute commands on a snapshot. Use a real Server object instead."
584
591
)
592
+ raise NotImplementedError (error_msg )
585
593
586
594
@property
587
595
def sessions (self ) -> QueryList [SessionSnapshot ]:
@@ -619,7 +627,8 @@ def raise_if_dead(self) -> None:
619
627
ConnectionError
620
628
Always raised since snapshots are not connected to a live tmux server
621
629
"""
622
- raise ConnectionError ("ServerSnapshot is not connected to a live tmux server" )
630
+ error_msg = "ServerSnapshot is not connected to a live tmux server"
631
+ raise ConnectionError (error_msg )
623
632
624
633
@classmethod
625
634
def from_server (
@@ -676,7 +685,10 @@ def from_server(
676
685
if "test" in sys .modules :
677
686
import warnings
678
687
679
- warnings .warn (f"Failed to create session snapshot: { e } " )
688
+ warnings .warn (
689
+ f"Failed to create session snapshot: { e } " ,
690
+ stacklevel = 2 ,
691
+ )
680
692
continue
681
693
else :
682
694
raise
0 commit comments