8000 Docstring updates, bolster linting by tony · Pull Request #514 · tmux-python/libtmux · GitHub
[go: up one dir, main page]

Skip to content

Docstring updates, bolster linting #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ruff format (after adding flake8-commas)
  • Loading branch information
tony committed Feb 6, 2024
commit 9a138dfe7d2f163b258e01c97a9107a17d44e224
4 changes: 3 additions & 1 deletion src/libtmux/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def keygetter(


def parse_lookup(
obj: "Mapping[str, t.Any]", path: str, lookup: str,
obj: "Mapping[str, t.Any]",
path: str,
lookup: str,
) -> t.Optional[t.Any]:
"""Check if field lookup key, e.g. "my__path__contains" has comparator, return val.

Expand Down
16 changes: 12 additions & 4 deletions src/libtmux/_vendor/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,18 @@
],
]
CmpKey = Tuple[
int, Tuple[int, ...], PrePostDevType, PrePostDevType, PrePostDevType, LocalType,
int,
Tuple[int, ...],
PrePostDevType,
PrePostDevType,
PrePostDevType,
LocalType,
]
VersionComparisonMethod = Callable[[CmpKey, CmpKey], bool]

_Version = collections.namedtuple(
"_Version", ["epoch", "release", "dev", "pre", "post", "local"],
"_Version",
["epoch", "release", "dev", "pre", "post", "local"],
)


Expand Down Expand Up @@ -220,7 +226,8 @@ def __init__(self, version: str) -> None:
release=tuple(int(i) for i in match.group("release").split(".")),
pre=_parse_letter_version(match.group("pre_l"), match.group("pre_n")),
post=_parse_letter_version(
match.group("post_l"), match.group("post_n1") or match.group("post_n2"),
match.group("post_l"),
match.group("post_n1") or match.group("post_n2"),
),
dev=_parse_letter_version(match.group("dev_l"), match.group("dev_n")),
local=_parse_local_version(match.group("local")),
Expand Down Expand Up @@ -468,7 +475,8 @@ def micro(self) -> int:


def _parse_letter_version(
letter: str, number: Union[str, bytes, SupportsInt],
letter: str,
number: Union[str, bytes, SupportsInt],
) -> Optional[Tuple[str, int]]:
if letter:
# We consider there to be an implicit 0 in a pre-release if there is
Expand Down
10 changes: 7 additions & 3 deletions src/libtmux/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:

try:
self.process = subprocess.Popen(
cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = self.process.communicate()
returncode = self.process.returncode
Expand All @@ -255,7 +257,8 @@ def __init__(self, *args: t.Any, **kwargs: t.Any) -> None:

logger.debug(
"self.stdout for {cmd}: {stdout}".format(
cmd=" ".join(cmd), stdout=self.stdout,
cmd=" ".join(cmd),
stdout=self.stdout,
),
)

Expand Down Expand Up @@ -409,7 +412,8 @@ def has_minimum_version(raises: bool = True) -> bool:
raise exc.VersionTooLow(
"libtmux only supports tmux {} and greater. This system"
" has {} installed. Upgrade your tmux to use libtmux.".format(
TMUX_MIN_VERSION, get_version(),
TMUX_MIN_VERSION,
get_version(),
),
)
else:
Expand Down
5 changes: 4 additions & 1 deletion src/libtmux/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ class BadSessionName(LibTmuxException):
"""Disallowed session name for tmux (empty, contains periods or colons)."""

def __init__(
self, reason: str, session_name: t.Optional[str] = None, *args: object,
self,
reason: str,
session_name: t.Optional[str] = None,
*args: object,
):
msg = f"Bad session name: {reason}"
if session_name is not None:
Expand Down
9 changes: 7 additions & 2 deletions src/libtmux/neo.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,10 @@ def _refresh(
) -> None:
assert isinstance(obj_id, str)
obj = fetch_obj(
obj_key=obj_key, obj_id=obj_id, list_cmd=list_cmd, server=self.server,
obj_key=obj_key,
obj_id=obj_id,
list_cmd=list_cmd,
server=self.server,
)
assert obj is not None
if obj is not None:
Expand Down Expand Up @@ -233,7 +236,9 @@ def fetch_obj(
) -> OutputRaw:
"""Fetch raw data from tmux command."""
obj_formatters_filtered = fetch_objs(
server=server, list_cmd=list_cmd, list_extra_args=list_extra_args,
server=server,
list_cmd=list_cmd,
list_extra_args=list_extra_args,
)

obj = None
Expand Down
8 changes: 6 additions & 2 deletions src/libtmux/pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,9 @@ def send_keys(

@overload
def display_message(
self, cmd: str, get_text: "t.Literal[True]",
self,
cmd: str,
get_text: "t.Literal[True]",
) -> t.Union[str, t.List[str]]:
...

Expand All @@ -254,7 +256,9 @@ def display_message(self, cmd: str, get_text: "t.Literal[False]") -> None:
...

def display_message(
self, cmd: str, get_text: bool = False,
self,
cmd: str,
get_text: bool = False,
) -> t.Optional[t.Union[str, t.List[str]]]:
"""Display message to pane.

Expand Down
4 changes: 3 additions & 1 deletion src/libtmux/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def session_params() -> t.Dict[str, t.Any]:

@pytest.fixture(scope="function")
def session(
request: pytest.FixtureRequest, session_params: t.Dict[str, t.Any], server: Server,
request: pytest.FixtureRequest,
session_params: t.Dict[str, t.Any],
server: Server,
) -> "Session":
"""Return new, temporary :class:`libtmux.Session`.

Expand Down
3 changes: 2 additions & 1 deletion src/libtmux/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ def new_session(
)

return Session.from_session_id(
server=self, session_id=session_formatters["session_id"],
server=self,
session_id=session_formatters["session_id"],
)

#
Expand Down
22 changes: 16 additions & 6 deletions src/libtmux/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ def refresh(self) -> None:
"""Refresh session attributes from tmux."""
assert isinstance(self.session_id, str)
return super()._refresh(
obj_key="session_id", obj_id=self.session_id, list_cmd="list-sessions",
obj_key="session_id",
obj_id=self.session_id,
list_cmd="list-sessions",
)

@classmethod
Expand Down Expand Up @@ -169,7 +171,10 @@ def cmd(self, *args: t.Any, **kwargs: t.Any) -> tmux_cmd:
"""

def set_option(
self, option: str, value: t.Union[str, int], _global: bool = False,
self,
option: str,
value: t.Union[str, int],
_global: bool = False,
) -> "Session":
"""Set option ``$ tmux set-option <option> <value>``.

Expand Down Expand Up @@ -220,7 +225,8 @@ def set_option(
return self

def show_options(
self, _global: t.Optional[bool] = False,
self,
_global: t.Optional[bool] = False,
) -> t.Dict[str, t.Union[str, int]]:
"""Return dict of options for the session.

Expand Down Expand Up @@ -258,7 +264,9 @@ def show_options(
return session_options

def show_option(
self, option: str, _global: bool = False,
self,
option: str,
_global: bool = False,
) -> t.Optional[t.Union[str, int, bool]]:
"""Return option value for the target session.

Expand Down Expand Up @@ -506,7 +514,8 @@ def new_window(
)

return Window.from_window_id(
server=self.server, window_id=window_formatters["window_id"],
server=self.server,
window_id=window_formatters["window_id"],
)

def kill_window(self, target_window: t.Optional[str] = None) -> None:
Expand Down Expand Up @@ -604,7 +613,8 @@ def __getitem__(self, key: str) -> t.Any:

"""
warnings.warn(
f"Item lookups, e.g. session['{key}'] is deprecated", stacklevel=2,
f"Item lookups, e.g. session['{key}'] is deprecated",
stacklevel=2,
)
return getattr(self, key)

Expand Down
14 changes: 10 additions & 4 deletions src/libtmux/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ class RandomStrSequence:
"""Factory to generate random string."""

def __init__(
self, characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_",
self,
characters: str = "abcdefghijklmnopqrstuvwxyz0123456789_",
) -> None:
"""Create a random letter / number generator. 8 chars in length.

Expand Down Expand Up @@ -141,7 +142,8 @@ def get_test_session_name(server: "Server", prefix: str = TEST_SESSION_PREFIX) -


def get_test_window_name(
session: "Session", prefix: t.Optional[str] = TEST_SESSION_PREFIX,
session: "Session",
prefix: t.Optional[str] = TEST_SESSION_PREFIX,
) -> str:
"""
Faker to create a window name that doesn't exist.
Expand Down Expand Up @@ -180,7 +182,9 @@ def get_test_window_name(

@contextlib.contextmanager
def temp_session(
server: Server, *args: t.Any, **kwargs: t.Any,
server: Server,
*args: t.Any,
**kwargs: t.Any,
) -> t.Generator["Session", t.Any, t.Any]:
"""
Return a context manager with a temporary session.
Expand Down Expand Up @@ -230,7 +234,9 @@ def temp_session(

@contextlib.contextmanager
def temp_window(
session: "Session", *args: t.Any, **kwargs: t.Any,
session: "Session",
*args: t.Any,
**kwargs: t.Any,
) -> t.Generator["Window", t.Any, t.Any]:
"""
Return a context manager with a temporary window.
Expand Down
8 changes: 6 additions & 2 deletions src/libtmux/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,9 @@ def show_window_options(self, g: t.Optional[bool] = False) -> "WindowOptionDict"
return window_options

def show_window_option(
self, option: str, g: bool = False,
self,
option: str,
g: bool = False,
) -> t.Optional[t.Union[str, int]]:
"""Return option value for the target window.

Expand Down Expand Up @@ -486,7 +488,9 @@ def kill_window(self) -> None:
raise exc.LibTmuxException(proc.stderr)

def move_window(
self, destination: str = "", session: t.Optional[str] = None,
self,
destination: str = "",
session: t.Optional[str] = None,
) -> "Window":
"""Move current :class:`Window` object ``$ tmux move-window``.

Expand Down
4 changes: 3 additions & 1 deletion tests/legacy_api/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class SessionCheckName(t.NamedTuple):
],
)
def test_session_check_name(
session_name: t.Optional[str], raises: bool, exc_msg_regex: t.Optional[str],
session_name: t.Optional[str],
raises: bool,
exc_msg_regex: t.Optional[str],
) -> None:
"""Verify session_check_name()."""
if raises:
Expand Down
4 changes: 3 additions & 1 deletion tests/legacy_api/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ def test_capture_pane(session: Session) -> None:
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane.send_keys(
r'printf "\n%s\n" "Hello World !"', literal=True, suppress_history=False,
r'printf "\n%s\n" "Hello World !"',
literal=True,
suppress_history=False,
)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
Expand Down
5 changes: 4 additions & 1 deletion tests/legacy_api/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ def test_unset_environment(session: Session) -> None:
[("hey.period", True), ("hey:its a colon", True), ("hey moo", False)],
)
def test_periods_raise_badsessionname(
server: Server, session: Session, session_name: str, raises: bool,
server: Server,
session: Session,
session_name: str,
raises: bool,
) -> None:
"""Verify session names with periods raise BadSessionName."""
new_name = session_name + "moo" # used for rename / switch
Expand Down
7 changes: 5 additions & 2 deletions tests/legacy_api/test_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ def test_split_window_horizontal(session: Session) -> None:
[("test", "ha ha ha fjewlkjflwef"), ("test", "hello \\ wazzup 0")],
)
def test_window_rename(
session: Session, window_name_before: str, window_name_after: str,
session: Session,
window_name_before: str,
window_name_after: str,
) -> None:
"""Test Window.rename_window()."""
window_name_before = "test"
Expand Down Expand Up @@ -308,7 +310,8 @@ def test_select_layout_accepts_no_arg(server: Server, session: Session) -> None:


@pytest.mark.skipif(
has_lt_version("3.2"), reason="needs filter introduced in tmux >= 3.2",
has_lt_version("3.2"),
reason="needs filter introduced in tmux >= 3.2",
)
def test_empty_window_name(session: Session) -> None:
"""New windows can be created with empty string for window name."""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@ class SessionCheckName(t.NamedTuple):
],
)
def test_session_check_name(
session_name: t.Optional[str], raises: bool, exc_msg_regex: t.Optional[str],
session_name: t.Optional[str],
raises: bool,
exc_msg_regex: t.Optional[str],
) -> None:
"""Verify session_check_name()."""
if raises:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_pane.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,9 @@ def test_capture_pane(session: Session) -> None:
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == "$"
pane.send_keys(
r'printf "\n%s\n" "Hello World !"', literal=True, suppress_history=False,
r'printf "\n%s\n" "Hello World !"',
literal=True,
suppress_history=False,
)
pane_contents = "\n".join(pane.capture_pane())
assert pane_contents == r'$ printf "\n%s\n" "Hello World !"{}'.format(
Expand Down
5 changes: 4 additions & 1 deletion tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,10 @@ class PeriodRaisesBadSessionName(t.NamedTuple):
],
)
def test_periods_raise_bad_session_name(
server: Server, session: Session, session_name: str, raises: bool,
server: Server,
session: Session,
session_name: str,
raises: bool,
) -> None:
"""Verify session names with periods raise BadSessionName."""
new_name = session_name + "moo" # used for rename / switch
Expand Down
Loading
0