Skip to content

Commit d3cb278

Browse files
committed
refactor!(ruff): Run all automated fixes as of ruff 0.3.4
ruff check --select ALL . --fix --unsafe-fixes --preview --show-fixes; ruff format . Fixed 144 errors: - conftest.py: 2 × I001 (unsorted-imports) 2 × PT003 (pytest-extraneous-scope-function) 1 × PIE790 (unnecessary-placeholder) 1 × TCH005 (empty-type-checking-block) 1 × TCH004 (runtime-import-in-type-checking-block) - docs/conf.py: 1 × RET505 (superfluous-else-return) - src/libtmux/_internal/query_list.py: 3 × RSE102 (unnecessary-paren-on-raise-exception) 2 × ANN204 (missing-return-type-special-method) 1 × T201 (print) 1 × PLR5501 (collapsible-else-if) 1 × RET505 (superfluous-else-return) 1 × RET506 (superfluous-else-raise) 1 × F841 (unused-variable) - src/libtmux/_vendor/version.py: 2 × PLR6201 (literal-membership) 1 × ANN204 (missing-return-type-special-method) 1 × RET505 (superfluous-else-return) 1 × RUF022 (unsorted-dunder-all) - src/libtmux/common.py: 6 × RET506 (superfluous-else-raise) 1 × RSE102 (unnecessary-paren-on-raise-exception) 1 × TCH005 (empty-type-checking-block) 1 × I001 (unsorted-imports) - src/libtmux/exc.py: 8 × ANN204 (missing-return-type-special-method) 2 × PIE790 (unnecessary-placeholder) 2 × COM812 (missing-trailing-comma) 2 × E303 (too-many-blank-lines) - src/libtmux/neo.py: 1 × E303 (too-many-blank-lines) 1 × RET504 (unnecessary-assign) - src/libtmux/pane.py: 3 × E266 (multiple-leading-hashes-for-block-comment) 2 × COM812 (missing-trailing-comma) 1 × RSE102 (unnecessary-paren-on-raise-exception) 1 × E303 (too-many-blank-lines) 1 × PLR1711 (useless-return) - src/libtmux/pytest_plugin.py: 3 × PT003 (pytest-extraneous-scope-function) 1 × PT001 (pytest-fixture-incorrect-parentheses-style) - src/libtmux/server.py: 2 × ISC001 (single-line-implicit-string-concatenation) 2 × RSE102 (unnecessary-paren-on-raise-exception) 2 × COM812 (missing-trailing-comma) 1 × RET505 (superfluous-else-return) 1 × SIM103 (needless-bool) - src/libtmux/session.py: 5 × COM812 (missing-trailing-comma) 2 × RSE102 (unnecessary-paren-on-raise-exception) 1 × RET506 (superfluous-else-raise) 1 × RET505 (superfluous-else-return) 1 × RET503 (implicit-return) 1 × PLR1711 (useless-return) 1 × E303 (too-many-blank-lines) - src/libtmux/test.py: 1 × RET506 (superfluous-else-raise) 1 × RSE102 (unnecessary-paren-on-raise-exception) - src/libtmux/window.py: 4 × COM812 (missing-trailing-comma) 2 × E266 (multiple-leading-hashes-for-block-comment) 1 × RSE102 (unnecessary-paren-on-raise-exception) 1 × E303 (too-many-blank-lines) 1 × PLR6201 (literal-membership) 1 × PLR1711 (useless-return) - tests/_internal/test_query_list.py: 38 × PT007 (pytest-parametrize-values-wrong-type) 1 × PT006 (pytest-parametrize-names-wrong-type) - tests/legacy_api/test_session.py: 1 × PT006 (pytest-parametrize-names-wrong-type) - tests/legacy_api/test_version.py: 1 × PT014 (pytest-duplicate-parametrize-test-cases) - tests/legacy_api/test_window.py: 1 × COM812 (missing-trailing-comma) 1 × PT006 (pytest-parametrize-names-wrong-type) - tests/test_dataclasses.py: 1 × COM812 (missing-trailing-comma) 1 × PT001 (pytest-fixture-incorrect-parentheses-style) - tests/test_session.py: 2 × COM812 (missing-trailing-comma) - tests/test_version.py: 1 × PT014 (pytest-duplicate-parametrize-test-cases) - tests/test_window.py: 3 × COM812 (missing-trailing-comma) 1 × PT006 (pytest-parametrize-names-wrong-type)
1 parent 3eb0599 commit d3cb278

21 files changed

+192
-193
lines changed

conftest.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
from libtmux.session import Session
2222
from libtmux.window import Window
2323

24-
if t.TYPE_CHECKING:
25-
from libtmux.session import Session
26-
2724
pytest_plugins = ["pytester"]
2825

2926

@@ -47,7 +44,7 @@ def add_doctest_fixtures(
4744
doctest_namespace["request"] = request
4845

4946

50-
@pytest.fixture(autouse=True, scope="function")
47+
@pytest.fixture(autouse=True)
5148
def set_home(
5249
monkeypatch: pytest.MonkeyPatch,
5350
user_path: pathlib.Path,
@@ -56,12 +53,11 @@ def set_home(
5653
monkeypatch.setenv("HOME", str(user_path))
5754

5855

59-
@pytest.fixture(autouse=True, scope="function")
56+
@pytest.fixture(autouse=True)
6057
def setup_fn(
6158
clear_env: None,
6259
) -> None:
6360
"""Function-level test configuration fixtures for pytest."""
64-
pass
6561

6662

6763
@pytest.fixture(autouse=True, scope="session")

docs/conf.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,14 @@ def linkcode_resolve(domain: str, info: t.Dict[str, str]) -> t.Union[None, str]:
197197
fn,
198198
linespec,
199199
)
200-
else:
201-
return "{}/blob/v{}/{}/{}/{}{}".format(
202-
about["__github__"],
203-
about["__version__"],
204-
"src",
205-
about["__package_name__"],
206-
fn,
207-
linespec,
208-
)
200+
return "{}/blob/v{}/{}/{}/{}{}".format(
201+
about["__github__"],
202+
about["__version__"],
203+
"src",
204+
about["__package_name__"],
205+
fn,
206+
linespec,
207+
)
209208

210209

211210
def remove_tabs_js(app: "Sphinx", exc: Exception) -> None:

src/libtmux/_internal/query_list.py

+10-13
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,8 @@ def keygetter(
100100
elif hasattr(dct, sub_field):
101101
dct = getattr(dct, sub_field)
102102

103-
except Exception as e:
103+
except Exception:
104104
traceback.print_stack()
105-
print(f"Above error was {e}")
106105
return None
107106

108107
return dct
@@ -307,12 +306,12 @@ def lookup_iregex(
307306

308307

309308
class PKRequiredException(Exception):
310-
def __init__(self, *args: object):
309+
def __init__(self, *args: object) -> None:
311310
return super().__init__("items() require a pk_key exists")
312311

313312

314313
class OpNotFound(ValueError):
315-
def __init__(self, op: str, *args: object):
314+
def __init__(self, op: str, *args: object) -> None:
316315
return super().__init__(f"{op} not in LOOKUP_NAME_MAP")
317316

318317

@@ -473,7 +472,7 @@ def __init__(self, items: t.Optional["Iterable[T]"] = None) -> None:
473472

474473
def items(self) -> t.List[t.Tuple[str, T]]:
475474
if self.pk_key is None:
476-
raise PKRequiredException()
475+
raise PKRequiredException
477476
return [(getattr(item, self.pk_key), item) for item in self]
478477

479478
def __eq__(
@@ -493,9 +492,8 @@ def __eq__(
493492
for key in a_keys:
494493
if abs(a[key] - b[key]) > 1:
495494
return False
496-
else:
497-
if a != b:
498-
return False
495+
elif a != b:
496+
return False
499497

500498
return True
501499
return False
@@ -534,8 +532,7 @@ def filter_lookup(obj: t.Any) -> bool:
534532
def val_match(obj: t.Union[str, t.List[t.Any], T]) -> bool:
535533
if isinstance(matcher, list):
536534
return obj in matcher
537-
else:
538-
return bool(obj == matcher)
535+
return bool(obj == matcher)
539536

540537
_filter = val_match
541538
else:
@@ -557,9 +554,9 @@ def get(
557554
"""
558555
objs = self.filter(matcher=matcher, **kwargs)
559556
if len(objs) > 1:
560-
raise MultipleObjectsReturned()
561-
elif len(objs) == 0:
557+
raise MultipleObjectsReturned
558+
if len(objs) == 0:
562559
if default == no_arg:
563-
raise ObjectDoesNotExist()
560+
raise ObjectDoesNotExist
564561
return default
565562
return objs[0]

src/libtmux/_vendor/version.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
from ._structures import Infinity, InfinityType, NegativeInfinity, NegativeInfinityType
1818

19-
__all__ = ["VERSION_PATTERN", "parse", "Version", "InvalidVersion"]
19+
__all__ = ["VERSION_PATTERN", "InvalidVersion", "Version", "parse"]
2020

2121
InfiniteTypes = Union[InfinityType, NegativeInfinityType]
2222
PrePostDevType = Union[InfiniteTypes, Tuple[str, int]]
@@ -78,7 +78,7 @@ class InvalidVersion(ValueError):
7878
libtmux._vendor.version.InvalidVersion: Invalid version: 'invalid'
7979
"""
8080

81-
def __init__(self, version: str, *args: object):
81+
def __init__(self, version: str, *args: object) -> None:
8282
return super().__init__(f"Invalid version: '{version}'")
8383

8484

@@ -362,8 +362,7 @@ def local(self) -> Optional[str]:
362362
"""
363363
if self._version.local:
364364
return ".".join(str(x) for x in self._version.local)
365-
else:
366-
return None
365+
return None
367366

368367
@property
369368
def public(self) -> str:
@@ -494,9 +493,9 @@ def _parse_letter_version(
494493
letter = "a"
495494
elif letter == "beta":
496495
letter = "b"
497-
elif letter in ["c", "pre", "preview"]:
496+
elif letter in {"c", "pre", "preview"}:
498497
letter = "rc"
499-
elif letter in ["rev", "r"]:
498+
elif letter in {"rev", "r"}:
500499
letter = "post"
501500

502501
return letter, int(number)

src/libtmux/common.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
from . import exc
1717
from ._compat import LooseVersion, console_to_str, str_from_console
1818

19-
if t.TYPE_CHECKING:
20-
pass
21-
22-
2319
logger = logging.getLogger(__name__)
2420

2521

@@ -219,7 +215,7 @@ class tmux_cmd:
219215
def __init__(self, *args: t.Any) -> None:
220216
tmux_bin = shutil.which("tmux")
221217
if not tmux_bin:
222-
raise exc.TmuxCommandNotFound()
218+
raise exc.TmuxCommandNotFound
223219

224220
cmd = [tmux_bin]
225221
cmd += args # add the command arguments to cmd
@@ -416,8 +412,7 @@ def has_minimum_version(raises: bool = True) -> bool:
416412
+ "libtmux."
417413
)
418414
raise exc.VersionTooLow(msg)
419-
else:
420-
return False
415+
return False
421416
return True
422417

423418

@@ -439,9 +434,9 @@ def session_check_name(session_name: t.Optional[str]) -> None:
439434
"""
440435
if session_name is None or len(session_name) == 0:
441436
raise exc.BadSessionName(reason="empty", session_name=session_name)
442-
elif "." in session_name:
437+
if "." in session_name:
443438
raise exc.BadSessionName(reason="contains periods", session_name=session_name)
444-
elif ":" in session_name:
439+
if ":" in session_name:
445440
raise exc.BadSessionName(reason="contains colons", session_name=session_name)
446441

447442

@@ -474,12 +469,11 @@ def handle_option_error(error: str) -> t.Type[exc.OptionError]:
474469
"""
475470
if "unknown option" in error:
476471
raise exc.UnknownOption(error)
477-
elif "invalid option" in error:
472+
if "invalid option" in error:
478473
raise exc.InvalidOption(error)
479-
elif "ambiguous option" in error:
474+
if "ambiguous option" in error:
480475
raise exc.AmbiguousOption(error)
481-
else:
482-
raise exc.OptionError(error) # Raise generic option error
476+
raise exc.OptionError(error) # Raise generic option error
483477

484478

485479
def get_libtmux_version() -> LooseVersion:

src/libtmux/exc.py

+12-14
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
list_cmd: t.Optional[str] = None,
3636
list_extra_args: "t.Optional[ListExtraArgs]" = None,
3737
*args: object,
38-
):
38+
) -> None:
3939
if all(arg is not None for arg in [obj_key, obj_id, list_cmd, list_extra_args]):
4040
return super().__init__(
4141
f"Could not find {obj_key}={obj_id} for {list_cmd} "
@@ -56,7 +56,7 @@ def __init__(
5656
reason: str,
5757
session_name: t.Optional[str] = None,
5858
*args: object,
59-
):
59+
) -> None:
6060
msg = f"Bad session name: {reason}"
6161
if session_name is not None:
6262
msg += f" (session name: {session_name})"
@@ -74,7 +74,7 @@ class UnknownOption(OptionError):
7474
class UnknownColorOption(UnknownOption):
7575
"""Unknown color option."""
7676

77-
def __init__(self, *args: object):
77+
def __init__(self, *args: object) -> None:
7878
return super().__init__("Server.colors must equal 88 or 256")
7979

8080

@@ -93,7 +93,7 @@ class WaitTimeout(LibTmuxException):
9393
class VariableUnpackingError(LibTmuxException):
9494
"""Error unpacking variable."""
9595

96-
def __init__(self, variable: t.Optional[t.Any] = None, *args: object):
96+
def __init__(self, variable: t.Optional[t.Any] = None, *args: object) -> None:
9797
return super().__init__(f"Unexpected variable: {variable!s}")
9898

9999

@@ -104,7 +104,7 @@ class PaneError(LibTmuxException):
104104
class PaneNotFound(PaneError):
105105
"""Pane not found."""
106106

107-
def __init__(self, pane_id: t.Optional[str] = None, *args: object):
107+
def __init__(self, pane_id: t.Optional[str] = None, *args: object) -> None:
108108
if pane_id is not None:
109109
return super().__init__(f"Pane not found: {pane_id}")
110110
return super().__init__("Pane not found")
@@ -117,21 +117,21 @@ class WindowError(LibTmuxException):
117117
class MultipleActiveWindows(WindowError):
118118
"""Multiple active windows."""
119119

120-
def __init__(self, count: int, *args: object):
120+
def __init__(self, count: int, *args: object) -> None:
121121
return super().__init__(f"Multiple active windows: {count} found")
122122

123123

124124
class NoActiveWindow(WindowError):
125125
"""No active window found."""
126126

127-
def __init__(self, *args: object):
127+
def __init__(self, *args: object) -> None:
128128
return super().__init__("No active windows found")
129129

130130

131131
class NoWindowsExist(WindowError):
132132
"""No windows exist for object."""
133133

134-
def __init__(self, *args: object):
134+
def __init__(self, *args: object) -> None:
135135
return super().__init__("No windows exist for object")
136136

137137

@@ -143,20 +143,18 @@ def __init__(self) -> None:
143143

144144

145145
class WindowAdjustmentDirectionRequiresAdjustment(
146-
WindowError, AdjustmentDirectionRequiresAdjustment
146+
WindowError,
147+
AdjustmentDirectionRequiresAdjustment,
147148
):
148149
"""ValueError for :meth:`libtmux.Window.resize_window`."""
149150

150-
pass
151-
152151

153152
class PaneAdjustmentDirectionRequiresAdjustment(
154-
WindowError, AdjustmentDirectionRequiresAdjustment
153+
WindowError,
154+
AdjustmentDirectionRequiresAdjustment,
155155
):
156156
"""ValueError for :meth:`libtmux.Pane.resize_pane`."""
157157

158-
pass
159-
160158

161159
class RequiresDigitOrPercentage(LibTmuxException, ValueError):
162160
"""Requires digit (int or str digit) or a percentage."""

src/libtmux/neo.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,7 @@ def fetch_objs(
226226
]
227227

228228
# Filter empty values
229-
obj_formatters_filtered = [
230-
{k: v for k, v in formatter.items() if v} for formatter in obj_formatters
231-
]
232-
233-
return obj_formatters_filtered
229+
return [{k: v for k, v in formatter.items() if v} for formatter in obj_formatters]
234230

235231

236232
def fetch_obj(

src/libtmux/pane.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,16 @@ def resize(
215215
"""
216216
tmux_args: t.Tuple[str, ...] = ()
217217

218-
## Adjustments
218+
# Adjustments
219219
if adjustment_direction:
220220
if adjustment is None:
221-
raise exc.PaneAdjustmentDirectionRequiresAdjustment()
221+
raise exc.PaneAdjustmentDirectionRequiresAdjustment
222222
tmux_args += (
223223
f"{RESIZE_ADJUSTMENT_DIRECTION_FLAG_MAP[adjustment_direction]}",
224224
str(adjustment),
225225
)
226226
elif height or width:
227-
## Manual resizing
227+
# Manual resizing
228228
if height:
229229
if isinstance(height, str):
230230
if height.endswith("%") and not has_gte_version("3.1"):
@@ -242,7 +242,7 @@ def resize(
242242

243243
tmux_args += (f"-x{width}",)
244244
elif zoom:
245-
## Zoom / Unzoom
245+
# Zoom / Unzoom
246246
tmux_args += ("-Z",)
247247
elif mouse:
248248
tmux_args += ("-M",)
@@ -436,8 +436,6 @@ def kill(
436436
if proc.stderr:
437437
raise exc.LibTmuxException(proc.stderr)
438438

439-
return None
440-
441439
"""
442440
Commands ("climber"-helpers)
443441
@@ -650,7 +648,9 @@ def split(
650648
raise exc.LibTmuxException(pane_cmd.stderr)
651649

652650
raise exc.LibTmuxException(
653-
pane_cmd.stderr, self.__dict__, self.window.panes
651+
pane_cmd.stderr,
652+
self.__dict__,
653+
self.window.panes,
654654
)
655655

656656
pane_output = pane_cmd.stdout[0]
@@ -877,7 +877,9 @@ def get(self, key: str, default: t.Optional[t.Any] = None) -> t.Any:
877877
878878
"""
879879
warnings.warn(
880-
"Pane.get() is deprecated", category=DeprecationWarning, stacklevel=2
880+
"Pane.get() is deprecated",
881+
category=DeprecationWarning,
882+
stacklevel=2,
881883
)
882884
return getattr(self, key, default)
883885

0 commit comments

Comments
 (0)