Skip to content

Commit e33f19d

Browse files
committed
refactor!: Add typings from monkeytype
1 parent 5a2d9bf commit e33f19d

File tree

15 files changed

+128
-83
lines changed

15 files changed

+128
-83
lines changed

src/tmuxp/workspace/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def __init__(
188188
pass
189189

190190
@property
191-
def session(self):
191+
def session(self) -> Session:
192192
if self._session is None:
193193
raise exc.SessionMissingWorkspaceException()
194194
return self._session

src/tmuxp/workspace/freezer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from libtmux.window import Window
88

99

10-
def inline(workspace_dict):
10+
def inline(workspace_dict: t.Dict[str, t.Any]) -> t.Any:
1111
"""Return workspace with inlined shorthands. Opposite of :meth:`loader.expand`.
1212
1313
Parameters

src/tmuxp/workspace/loader.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import logging
88
import os
99
import pathlib
10-
from typing import Dict
10+
import typing as t
1111

1212
logger = logging.getLogger(__name__)
1313

@@ -30,7 +30,7 @@ def expandshell(value: str) -> str:
3030
return os.path.expandvars(os.path.expanduser(value)) # NOQA: PTH111
3131

3232

33-
def expand_cmd(p: Dict) -> Dict:
33+
def expand_cmd(p: t.Dict) -> t.Dict:
3434
if isinstance(p, str):
3535
p = {"shell_command": [p]}
3636
elif isinstance(p, list):
@@ -66,7 +66,11 @@ def expand_cmd(p: Dict) -> Dict:
6666
return p
6767

6868

69-
def expand(workspace_dict, cwd=None, parent=None):
69+
def expand(
70+
workspace_dict: t.Dict[str, t.Any],
71+
cwd: t.Optional[t.Union[pathlib.Path, str]] = None,
72+
parent: t.Optional[t.Any] = None,
73+
) -> t.Dict[str, t.Any]:
7074
"""Return workspace with shorthand and inline properties expanded.
7175
7276
This is necessary to keep the code in the :class:`WorkspaceBuilder` clean
@@ -185,7 +189,7 @@ def expand(workspace_dict, cwd=None, parent=None):
185189
return workspace_dict
186190

187191

188-
def trickle(workspace_dict):
192+
def trickle(workspace_dict: t.Dict[str, t.Any]) -> t.Dict[str, t.Any]:
189193
"""Return a dict with "trickled down" / inherited workspace values.
190194
191195
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
# In scrunched terminals, prevent width causing differantiation in result.out.
4646
monkeypatch.setenv("COLUMNS", "100")
@@ -86,7 +86,7 @@ def test_get_teamocil_dir(monkeypatch: pytest.MonkeyPatch) -> None:
8686
def test_pass_config_dir_ClickPath(
8787
tmp_path: pathlib.Path,
8888
monkeypatch: pytest.MonkeyPatch,
89-
capsys: pytest.CaptureFixture,
89+
capsys: pytest.CaptureFixture[str],
9090
) -> None:
9191
configdir = tmp_path / "myconfigdir"
9292
configdir.mkdir()

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
@@ -15,7 +15,7 @@ def test_import(
1515
cli_args: t.List[str],
1616
tmp_path: pathlib.Path,
1717
monkeypatch: pytest.MonkeyPatch,
18-
capsys: pytest.CaptureFixture,
18+
capsys: pytest.CaptureFixture[str],
1919
) -> None:
2020
cli.cli(cli_args)
2121
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],
@@ -318,7 +318,7 @@ def test_regression_00132_session_name_with_dots(
318318
tmp_path: pathlib.Path,
319319
server: "Server",
320320
session: Session,
321-
capsys: pytest.CaptureFixture,
321+
capsys: pytest.CaptureFixture[str],
322322
) -> None:
323323
yaml_config = FIXTURE_PATH / "workspace/builder" / "regression_00132_dots.yaml"
324324
cli_args = [str(yaml_config)]
@@ -333,7 +333,7 @@ def test_load_zsh_autotitle_warning(
333333
cli_args: t.List[str],
334334
tmp_path: pathlib.Path,
335335
monkeypatch: pytest.MonkeyPatch,
336-
capsys: pytest.CaptureFixture,
336+
capsys: pytest.CaptureFixture[str],
337337
server: "Server",
338338
) -> None:
339339
# create dummy tmuxp yaml so we don't get yelled at
@@ -392,7 +392,7 @@ def test_load_log_file(
392392
cli_args: t.List[str],
393393
tmp_path: pathlib.Path,
394394
monkeypatch: pytest.MonkeyPatch,
395-
capsys: pytest.CaptureFixture,
395+
capsys: pytest.CaptureFixture[str],
396396
) -> None:
397397
# create dummy tmuxp yaml that breaks to prevent actually loading tmux
398398
tmuxp_config_path = tmp_path / ".tmuxp.yaml"
@@ -450,7 +450,10 @@ def test_load_plugins(monkeypatch_plugin_test_packages: None) -> None:
450450
],
451451
)
452452
def test_load_plugins_version_fail_skip(
453-
monkeypatch_plugin_test_packages, cli_args, inputs, capsys: pytest.CaptureFixture
453+
monkeypatch_plugin_test_packages,
454+
cli_args,
455+
inputs,
456+
capsys: pytest.CaptureFixture[str],
454457
) -> None:
455458
with contextlib.suppress(SystemExit):
456459
cli.cli(cli_args)
@@ -474,7 +477,7 @@ def test_load_plugins_version_fail_no_skip(
474477
cli_args: t.List[str],
475478
inputs: t.List[str],
476479
monkeypatch: pytest.MonkeyPatch,
477-
capsys: pytest.CaptureFixture,
480+
capsys: pytest.CaptureFixture[str],
478481
) -> None:
479482
monkeypatch.setattr("sys.stdin", io.StringIO("".join(inputs)))
480483

@@ -493,7 +496,7 @@ def test_load_plugins_version_fail_no_skip(
493496
def test_load_plugins_plugin_missing(
494497
monkeypatch_plugin_test_packages: None,
495498
cli_args: t.List[str],
496-
capsys: pytest.CaptureFixture,
499+
capsys: pytest.CaptureFixture[str],
497500
) -> None:
498501
with contextlib.suppress(SystemExit):
499502
cli.cli(cli_args)
@@ -519,7 +522,7 @@ def test_plugin_system_before_script(
519522
session_file, socket_name=server.socket_name, detached=True
520523
)
521524

522-
assert isinstance(session, libtmux.Session)
525+
assert isinstance(session, Session)
523526
assert session.name == "plugin_test_bs"
524527

525528

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
@@ -90,7 +90,7 @@ def test_shell(
9090
session: Session,
9191
tmp_path: pathlib.Path,
9292
monkeypatch: pytest.MonkeyPatch,
93-
capsys: pytest.CaptureFixture,
93+
capsys: pytest.CaptureFixture[str],
9494
) -> None:
9595
monkeypatch.setenv("HOME", str(tmp_path))
9696
window_name = "my_window"
@@ -181,7 +181,7 @@ def test_shell_target_missing(
181181
session: Session,
182182
tmp_path: pathlib.Path,
183183
monkeypatch: pytest.MonkeyPatch,
184-
capsys: pytest.CaptureFixture,
184+
capsys: pytest.CaptureFixture[str],
185185
) -> None:
186186
monkeypatch.setenv("HOME", str(tmp_path))
187187
window_name = "my_window"
@@ -257,7 +257,7 @@ def test_shell_interactive(
257257
session: Session,
258258
tmp_path: pathlib.Path,
259259
monkeypatch: pytest.MonkeyPatch,
260-
capsys: pytest.CaptureFixture,
260+
capsys: pytest.CaptureFixture[str],
261261
) -> None:
262262
monkeypatch.setenv("HOME", str(tmp_path))
263263
window_name = "my_window"

tests/fixtures/workspace/expand1.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pathlib
2+
import typing as t
23

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

3233

33-
def after_workspace():
34+
def after_workspace() -> (
35+
t.Dict[
36+
str,
37+
t.Union[
38+
str,
39+
t.List[
40+
t.Union[
41+
t.Dict[
42+
str, t.Union[str, t.List[t.Dict[str, t.List[t.Dict[str, str]]]]]
43+
],
44+
t.Dict[
45+
str,
46+
t.Union[
47+
str,
48+
t.Dict[str, bool],
49+
t.List[t.Dict[str, t.List[t.Dict[str, str]]]],
50+
],
51+
],
52+
t.Dict[str, t.List[t.Dict[str, t.List[t.Dict[str, str]]]]],
53+
]
54+
],
55+
],
56+
]
57+
):
3458
return {
3559
"session_name": "sample workspace",
3660
"start_directory": str(pathlib.Path().home()),

0 commit comments

Comments
 (0)