Skip to content

Commit 6cfa6d9

Browse files
authored
refactor!(typings): Strict annotations (#383)
This also improves code quality in many places. By a lot. Even though there's still some `Any`'s floating around. This catches a lot of stuff.
2 parents 1b4fe96 + 1eb43c1 commit 6cfa6d9

24 files changed

+728
-439
lines changed

.tmuxp.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ windows:
1212
panes:
1313
- focus: true
1414
- pane
15+
- make watch_mypy
1516
- make watch_test
1617
- window_name: docs
1718
layout: main-horizontal

CHANGES

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ $ pip install --user --upgrade --pre libtmux
6161
window.show_window_option('DISPLAY')
6262
```
6363

64+
## What's new
65+
66+
- **Improved typings**
67+
68+
Now [`mypy --strict`] compliant ({issue}`383`)
69+
70+
[`mypy --strict`]: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict
71+
6472
### Development
6573

6674
- Fix incorrect function name `findWhere()` ({issue}`391`)

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,9 @@ watch_mypy:
5656

5757
format_markdown:
5858
prettier --parser=markdown -w *.md docs/*.md docs/**/*.md CHANGES
59+
60+
monkeytype_create:
61+
poetry run monkeytype run `poetry run which py.test`
62+
63+
monkeytype_apply:
64+
poetry run monkeytype list-modules | xargs -n1 -I{} sh -c 'poetry run monkeytype apply {}'

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# libtmux
22

3-
libtmux is a python scripting library for tmux. You can use it to command and control tmux servers,
3+
libtmux is a [typed](https://docs.python.org/3/library/typing.html) python scripting library for tmux. You can use it to command and control tmux servers,
44
sessions, windows, and panes. It is the tool powering [tmuxp], a tmux workspace manager.
55

66
[![Python Package](https://img.shields.io/pypi/v/libtmux.svg)](https://pypi.org/project/libtmux/)

docs/about.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
```
1616

17-
libtmux is an [abstraction layer] for tmux.
17+
libtmux is a [typed](https://docs.python.org/3/library/typing.html) [abstraction layer] for tmux.
1818

1919
It builds upon the concept of targets `-t`, to direct commands against
2020
individual session, windows and panes and `FORMATS`, template variables

docs/conf.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import sys
55
from os.path import dirname, relpath
66
from pathlib import Path
7-
from typing import Dict, List
7+
from typing import Dict, List, Union
88

99
import libtmux # NOQA
1010
from libtmux import test # NOQA
@@ -17,7 +17,7 @@
1717
sys.path.insert(0, str(cwd / "_ext"))
1818

1919
# package data
20-
about: Dict = {}
20+
about: Dict[str, str] = {}
2121
with open("../libtmux/__about__.py") as fp:
2222
exec(fp.read(), about)
2323

@@ -69,8 +69,8 @@
6969
html_css_files = ["css/custom.css"]
7070
html_extra_path = ["manifest.json"]
7171
html_theme = "furo"
72-
html_theme_path: List = []
73-
html_theme_options: Dict = {
72+
html_theme_path: List[str] = []
73+
html_theme_options: Dict[str, Union[str, List[Dict[str, str]]]] = {
7474
"light_logo": "img/libtmux.svg",
7575
"dark_logo": "img/libtmux.svg",
7676
"footer_icons": [
@@ -162,7 +162,9 @@
162162
intersphinx_mapping = {"http://docs.python.org/": None}
163163

164164

165-
def linkcode_resolve(domain, info): # NOQA: C901
165+
def linkcode_resolve(
166+
domain: str, info: Dict[str, str]
167+
) -> Union[None, str]: # NOQA: C901
166168
"""
167169
Determine the URL corresponding to Python object
168170
@@ -195,7 +197,8 @@ def linkcode_resolve(domain, info): # NOQA: C901
195197
except AttributeError:
196198
pass
197199
else:
198-
obj = unwrap(obj)
200+
if callable(obj):
201+
obj = unwrap(obj)
199202

200203
try:
201204
fn = inspect.getsourcefile(obj)

libtmux/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
__title__ = "libtmux"
22
__package_name__ = "libtmux"
33
__version__ = "0.12.0"
4-
__description__ = "Scripting library / ORM / API wrapper for tmux"
4+
__description__ = "Typed scripting library / ORM / API wrapper for tmux"
55
__email__ = "[email protected]"
66
__author__ = "Tony Narlock"
77
__github__ = "https://github.com/tmux-python/libtmux"

libtmux/_compat.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# flake8: NOQA
22
import sys
3+
import types
34
import typing as t
45

56
console_encoding = sys.__stdout__.encoding
@@ -14,7 +15,12 @@ def console_to_str(s: bytes) -> str:
1415

1516

1617
# TODO Consider removing, reraise does not seem to be called anywhere
17-
def reraise(tp, value, tb=None):
18+
def reraise(
19+
tp: t.Type[BaseException],
20+
value: BaseException,
21+
tb: types.TracebackType,
22+
) -> t.NoReturn:
23+
1824
if value.__traceback__ is not tb:
1925
raise (value.with_traceback(tb))
2026
raise value

0 commit comments

Comments
 (0)