Skip to content

Commit bb92f83

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 0454c82 commit bb92f83

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
@@ -74,7 +74,6 @@
7474
import re
7575
import shlex
7676
import typing as t
77-
import warnings
7877

7978
from libtmux._internal.sparse_array import SparseArray
8079
from libtmux.common import CmdMixin
@@ -671,12 +670,11 @@ def set_option(
671670
flags.append("-a")
672671

673672
if g is not None:
674-
warnings.warn(
675-
"g argument is deprecated in favor of global_",
676-
category=DeprecationWarning,
677-
stacklevel=2,
673+
raise exc.DeprecatedError(
674+
deprecated="g parameter",
675+
replacement="global_ parameter",
676+
version="0.50.0",
678677
)
679-
global_ = g
680678

681679
if global_ is not None and global_:
682680
assert isinstance(global_, bool)
@@ -831,13 +829,13 @@ def _show_options_raw(
831829
flags: tuple[str, ...] = ()
832830

833831
if g:
834-
warnings.warn(
835-
"g argument is deprecated in favor of global_",
836-
category=DeprecationWarning,
837-
stacklevel=2,
832+
raise exc.DeprecatedError(
833+
deprecated="g parameter",
834+
replacement="global_ parameter",
835+
version="0.50.0",
838836
)
839-
flags += ("-g",)
840-
elif global_:
837+
838+
if global_:
841839
flags += ("-g",)
842840

843841
if scope is not None and not isinstance(scope, _DefaultOptionScope):
@@ -1060,13 +1058,13 @@ def _show_option_raw(
10601058
flags: tuple[str | int, ...] = ()
10611059

10621060
if g:
1063-
warnings.warn(
1064-
"g argument is deprecated in favor of global_",
1065-
category=DeprecationWarning,
1066-
stacklevel=2,
1061+
raise exc.DeprecatedError(
1062+
deprecated="g parameter",
1063+
replacement="global_ parameter",
1064+
version="0.50.0",
10671065
)
1068-
flags += ("-g",)
1069-
elif global_:
1066+
1067+
if global_:
10701068
flags += ("-g",)
10711069

10721070
if scope is not None and not isinstance(scope, _DefaultOptionScope):
@@ -1239,12 +1237,11 @@ def show_option(
12391237
False
12401238
"""
12411239
if g:
1242-
warnings.warn(
1243-
"g argument is deprecated in favor of global_",
1244-
category=DeprecationWarning,
1245-
stacklevel=2,
1240+
raise exc.DeprecatedError(
1241+
deprecated="g parameter",
1242+
replacement="global_ parameter",
1243+
version="0.50.0",
12461244
)
1247-
global_ = g
12481245

12491246
return self._show_option(
12501247
option=option,

0 commit comments

Comments
 (0)