Skip to content

Commit 5d45156

Browse files
committed
refactor!: Add typings from monkeytype
1 parent 0c0406d commit 5d45156

File tree

15 files changed

+126
-84
lines changed

15 files changed

+126
-84
lines changed

src/tmuxp/workspace/builder.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import logging
88
import time
99
import typing as t
10+
from typing import Any, Dict, Iterator, List, Optional
1011

1112
from libtmux._internal.query_list import ObjectDoesNotExist
1213
from libtmux.common import has_lt_version
@@ -186,7 +187,7 @@ def __init__(
186187
pass
187188

188189
@property
189-
def session(self):
190+
def session(self) -> Session:
190191
if self._session is None:
191192
raise ObjectDoesNotExist(
192193
"No session object exists for WorkspaceBuilder. "

src/tmuxp/workspace/freezer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
import typing as t
2+
from typing import Any, Dict
3+
14
from libtmux.pane import Pane
25
from libtmux.session import Session
3-
import typing as t
46

57

6-
def inline(workspace_dict):
8+
def inline(workspace_dict: Dict[str, Any]) -> Any:
79
"""Return workspace with inlined shorthands. Opposite of :meth:`loader.expand`.
810
911
Parameters

src/tmuxp/workspace/loader.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
"""
77
import logging
88
import os
9-
from typing import Dict
9+
from pathlib import PosixPath
10+
from typing import Any, Dict, Optional, Union
1011

1112
logger = logging.getLogger(__name__)
1213

1314

14-
def expandshell(_path):
15+
def expandshell(_path: str) -> str:
1516
"""
1617
Return expanded path based on user's ``$HOME`` and ``env``.
1718
@@ -63,7 +64,11 @@ def expand_cmd(p: Dict) -> Dict:
6364
return p
6465

6566

66-
def expand(workspace_dict, cwd=None, parent=None):
67+
def expand(
68+
workspace_dict: Dict[str, Any],
69+
cwd: Optional[Union[PosixPath, str]] = None,
70+
parent: Optional[Any] = None,
71+
) -> Dict[str, Any]:
6772
"""Return workspace with shorthand and inline properties expanded.
6873
6974
This is necessary to keep the code in the :class:`WorkspaceBuilder` clean
@@ -183,7 +188,7 @@ def expand(workspace_dict, cwd=None, parent=None):
183188
return workspace_dict
184189

185190

186-
def trickle(workspace_dict):
191+
def trickle(workspace_dict: Dict[str, Any]) -> Dict[str, Any]:
187192
"""Return a dict with "trickled down" / inherited workspace values.
188193
189194
This will only work if workspace has been expanded to full form with

tests/cli/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_help(
4040
cli_args: t.List[str],
4141
tmp_path: pathlib.Path,
4242
monkeypatch: pytest.MonkeyPatch,
43-
capsys: pytest.CaptureFixture,
43+
capsys: pytest.CaptureFixture[str],
4444
) -> None:
4545
try:
4646
cli.cli(cli_args)
@@ -81,7 +81,7 @@ def test_get_teamocil_dir(monkeypatch: pytest.MonkeyPatch) -> None:
8181
def test_pass_config_dir_ClickPath(
8282
tmp_path: pathlib.Path,
8383
monkeypatch: pytest.MonkeyPatch,
84-
capsys: pytest.CaptureFixture,
84+
capsys: pytest.CaptureFixture[str],
8585
) -> None:
8686

8787
configdir = tmp_path / "myconfigdir"

tests/cli/test_debug_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def test_debug_info_cli(
99
monkeypatch: pytest.MonkeyPatch,
1010
tmp_path: pathlib.Path,
11-
capsys: pytest.CaptureFixture,
11+
capsys: pytest.CaptureFixture[str],
1212
) -> None:
1313
monkeypatch.setenv("SHELL", "/bin/bash")
1414

tests/cli/test_import.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_import(
1414
cli_args: t.List[str],
1515
tmp_path: pathlib.Path,
1616
monkeypatch: pytest.MonkeyPatch,
17-
capsys: pytest.CaptureFixture,
17+
capsys: pytest.CaptureFixture[str],
1818
) -> None:
1919
cli.cli(cli_args)
2020
result = capsys.readouterr()

tests/cli/test_load.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def test_load(
262262
tmuxp_configdir: pathlib.Path,
263263
server: "Server",
264264
session: Session,
265-
capsys: pytest.CaptureFixture,
265+
capsys: pytest.CaptureFixture[str],
266266
monkeypatch: pytest.MonkeyPatch,
267267
test_id: str,
268268
cli_args: t.List[str],
@@ -322,7 +322,7 @@ def test_regression_00132_session_name_with_dots(
322322
tmp_path: pathlib.Path,
323323
server: "Server",
324324
session: Session,
325-
capsys: pytest.CaptureFixture,
325+
capsys: pytest.CaptureFixture[str],
326326
) -> None:
327327
yaml_config = FIXTURE_PATH / "workspace/builder" / "regression_00132_dots.yaml"
328328
cli_args = [str(yaml_config)]
@@ -337,7 +337,7 @@ def test_load_zsh_autotitle_warning(
337337
cli_args: t.List[str],
338338
tmp_path: pathlib.Path,
339339
monkeypatch: pytest.MonkeyPatch,
340-
capsys: pytest.CaptureFixture,
340+
capsys: pytest.CaptureFixture[str],
341341
server: "Server",
342342
) -> None:
343343
# create dummy tmuxp yaml so we don't get yelled at
@@ -396,7 +396,7 @@ def test_load_log_file(
396396
cli_args: t.List[str],
397397
tmp_path: pathlib.Path,
398398
monkeypatch: pytest.MonkeyPatch,
399-
capsys: pytest.CaptureFixture,
399+
capsys: pytest.CaptureFixture[str],
400400
) -> None:
401401
# create dummy tmuxp yaml that breaks to prevent actually loading tmux
402402
tmuxp_config_path = tmp_path / ".tmuxp.yaml"
@@ -455,7 +455,10 @@ def test_load_plugins(monkeypatch_plugin_test_packages: None) -> None:
455455
],
456456
)
457457
def test_load_plugins_version_fail_skip(
458-
monkeypatch_plugin_test_packages, cli_args, inputs, capsys: pytest.CaptureFixture
458+
monkeypatch_plugin_test_packages,
459+
cli_args,
460+
inputs,
461+
capsys: pytest.CaptureFixture[str],
459462
) -> None:
460463
try:
461464
cli.cli(cli_args)
@@ -480,7 +483,7 @@ def test_load_plugins_version_fail_no_skip(
480483
cli_args: t.List[str],
481484
inputs: t.List[str],
482485
monkeypatch: pytest.MonkeyPatch,
483-
capsys: pytest.CaptureFixture,
486+
capsys: pytest.CaptureFixture[str],
484487
) -> None:
485488
monkeypatch.setattr("sys.stdin", io.StringIO("".join(inputs)))
486489

@@ -500,7 +503,7 @@ def test_load_plugins_version_fail_no_skip(
500503
def test_load_plugins_plugin_missing(
501504
monkeypatch_plugin_test_packages: None,
502505
cli_args: t.List[str],
503-
capsys: pytest.CaptureFixture,
506+
capsys: pytest.CaptureFixture[str],
504507
) -> None:
505508
try:
506509
cli.cli(cli_args)
@@ -527,7 +530,7 @@ def test_plugin_system_before_script(
527530
session_file, socket_name=server.socket_name, detached=True
528531
)
529532

530-
assert isinstance(session, libtmux.Session)
533+
assert isinstance(session, Session)
531534
assert session.name == "plugin_test_bs"
532535

533536

tests/cli/test_ls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
def test_ls_cli(
1010
monkeypatch: pytest.MonkeyPatch,
1111
tmp_path: pathlib.Path,
12-
capsys: pytest.CaptureFixture,
12+
capsys: pytest.CaptureFixture[str],
1313
) -> None:
1414
monkeypatch.setenv("HOME", str(tmp_path))
1515
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / ".config"))

tests/cli/test_shell.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_shell(
8989
session: Session,
9090
tmp_path: pathlib.Path,
9191
monkeypatch: pytest.MonkeyPatch,
92-
capsys: pytest.CaptureFixture,
92+
capsys: pytest.CaptureFixture[str],
9393
) -> None:
9494
monkeypatch.setenv("HOME", str(tmp_path))
9595
window_name = "my_window"
@@ -180,7 +180,7 @@ def test_shell_target_missing(
180180
session: Session,
181181
tmp_path: pathlib.Path,
182182
monkeypatch: pytest.MonkeyPatch,
183-
capsys: pytest.CaptureFixture,
183+
capsys: pytest.CaptureFixture[str],
184184
) -> None:
185185
monkeypatch.setenv("HOME", str(tmp_path))
186186
window_name = "my_window"
@@ -256,7 +256,7 @@ def test_shell_interactive(
256256
session: Session,
257257
tmp_path: pathlib.Path,
258258
monkeypatch: pytest.MonkeyPatch,
259-
capsys: pytest.CaptureFixture,
259+
capsys: pytest.CaptureFixture[str],
260260
) -> None:
261261
monkeypatch.setenv("HOME", str(tmp_path))
262262
window_name = "my_window"

tests/fixtures/workspace/expand1.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from typing import Dict, List, Union
23

34
before_workspace = {
45
"session_name": "sample workspace",
@@ -30,7 +31,22 @@
3031
}
3132

3233

33-
def after_workspace():
34+
def after_workspace() -> Dict[
35+
str,
36+
Union[
37+
str,
38+
List[
39+
Union[
40+
Dict[str, Union[str, List[Dict[str, List[Dict[str, str]]]]]],
41+
Dict[
42+
str,
43+
Union[str, Dict[str, bool], List[Dict[str, List[Dict[str, str]]]]],
44+
],
45+
Dict[str, List[Dict[str, List[Dict[str, str]]]]],
46+
]
47+
],
48+
],
49+
]:
3450
return {
3551
"session_name": "sample workspace",
3652
"start_directory": os.path.expanduser("~"),

tests/fixtures/workspace/expand2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from .. import utils as test_utils
44

55

6-
def unexpanded_yaml():
6+
def unexpanded_yaml() -> str:
77
return test_utils.read_workspace_file("workspace/expand2-unexpanded.yaml")
88

99

10-
def expanded_yaml():
10+
def expanded_yaml() -> str:
1111
return test_utils.read_workspace_file("workspace/expand2-expanded.yaml").format(
1212
HOME=os.path.expanduser("~")
1313
)

0 commit comments

Comments
 (0)