Skip to content

Commit 7f3afb6

Browse files
committed
options,hooks(refactor): Replace g param deprecation warning with error
why: Enforce migration from deprecated 'g' parameter to 'global_'. what: - options.py: set_option(), _show_options_raw(), _show_option_raw(), show_option() now raise DeprecatedError when g parameter is used - hooks.py: set_hook() now raises DeprecatedError when g parameter is used
1 parent c35079e commit 7f3afb6

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

src/libtmux/hooks.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
)
4848
from libtmux.options import handle_option_error
4949

50+
from . import exc
51+
5052
if t.TYPE_CHECKING:
5153
from typing_extensions import Self
5254

@@ -139,12 +141,11 @@ def set_hook(
139141
scope = self.default_hook_scope
140142

141143
if g:
142-
warnings.warn(
143-
"g argument is deprecated in favor of global_",
144-
category=DeprecationWarning,
145-
stacklevel=2,
144+
raise exc.DeprecatedError(
145+
deprecated="g parameter",
146+
replacement="global_ parameter",
147+
version="0.50.0",
146148
)
147-
global_ = g
148149

149150
flags: list[str] = []
150151

src/libtmux/options.py

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@
7272
import re
7373
import shlex
7474
import typing as t
75-
import warnings
7675

7776
from libtmux._internal.sparse_array import SparseArray
7877
from libtmux.common import CmdMixin
@@ -669,12 +668,11 @@ def set_option(
669668
flags.append("-a")
670669

671670
if g is not None:
672-
warnings.warn(
673-
"g argument is deprecated in favor of global_",
674-
category=DeprecationWarning,
675-
stacklevel=2,
671+
raise exc.DeprecatedError(
672+
deprecated="g parameter",
673+
replacement="global_ parameter",
674+
version="0.50.0",
676675
)
677-
global_ = g
678676

679677
if global_ is not None and global_:
680678
assert isinstance(global_, bool)
@@ -829,13 +827,13 @@ def _show_options_raw(
829827
flags: tuple[str, ...] = ()
830828

831829
if g:
832-
warnings.warn(
833-
"g argument is deprecated in favor of global_",
834-
category=DeprecationWarning,
835-
stacklevel=2,
830+
raise exc.DeprecatedError(
831+
deprecated="g parameter",
832+
replacement="global_ parameter",
833+
version="0.50.0",
836834
)
837-
flags += ("-g",)
838-
elif global_:
835+
836+
if global_:
839837
flags += ("-g",)
840838

841839
if scope is not None and not isinstance(scope, _DefaultOptionScope):
@@ -1058,13 +1056,13 @@ def _show_option_raw(
10581056
flags: tuple[str | int, ...] = ()
10591057

10601058
if g:
1061-
warnings.warn(
1062-
"g argument is deprecated in favor of global_",
1063-
category=DeprecationWarning,
1064-
stacklevel=2,
1059+
raise exc.DeprecatedError(
1060+
deprecated="g parameter",
1061+
replacement="global_ parameter",
1062+
version="0.50.0",
10651063
)
1066-
flags += ("-g",)
1067-
elif global_:
1064+
1065+
if global_:
10681066
flags += ("-g",)
10691067

10701068
if scope is not None and not isinstance(scope, _DefaultOptionScope):
@@ -1237,12 +1235,11 @@ def show_option(
12371235
False
12381236
"""
12391237
if g:
1240-
warnings.warn(
1241-
"g argument is deprecated in favor of global_",
1242-
category=DeprecationWarning,
1243-
stacklevel=2,
1238+
raise exc.DeprecatedError(
1239+
deprecated="g parameter",
1240+
replacement="global_ parameter",
1241+
version="0.50.0",
12441242
)
1245-
global_ = g
12461243

12471244
return self._show_option(
12481245
option=option,

0 commit comments

Comments
 (0)