Skip to content

Mypy: Strict annotations #383

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 10 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .tmuxp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ windows:
panes:
- focus: true
- pane
- make watch_mypy
- make watch_test
- window_name: docs
layout: main-horizontal
Expand Down
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ $ pip install --user --upgrade --pre libtmux
window.show_window_option('DISPLAY')
```

## What's new

- **Improved typings**

Now [`mypy --strict`] compliant ({issue}`383`)

[`mypy --strict`]: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-strict

### Development

- Fix incorrect function name `findWhere()` ({issue}`391`)
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,9 @@ watch_mypy:

format_markdown:
prettier --parser=markdown -w *.md docs/*.md docs/**/*.md CHANGES

monkeytype_create:
poetry run monkeytype run `poetry run which py.test`

monkeytype_apply:
poetry run monkeytype list-modules | xargs -n1 -I{} sh -c 'poetry run monkeytype apply {}'
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# libtmux

libtmux is a python scripting library for tmux. You can use it to command and control tmux servers,
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,
sessions, windows, and panes. It is the tool powering [tmuxp], a tmux workspace manager.

[![Python Package](https://img.shields.io/pypi/v/libtmux.svg)](https://pypi.org/project/libtmux/)
Expand Down
2 changes: 1 addition & 1 deletion docs/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

```

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

It builds upon the concept of targets `-t`, to direct commands against
individual session, windows and panes and `FORMATS`, template variables
Expand Down
15 changes: 9 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
from os.path import dirname, relpath
from pathlib import Path
from typing import Dict, List
from typing import Dict, List, Union

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

# package data
about: Dict = {}
about: Dict[str, str] = {}
with open("../libtmux/__about__.py") as fp:
exec(fp.read(), about)

Expand Down Expand Up @@ -69,8 +69,8 @@
html_css_files = ["css/custom.css"]
html_extra_path = ["manifest.json"]
html_theme = "furo"
html_theme_path: List = []
html_theme_options: Dict = {
html_theme_path: List[str] = []
html_theme_options: Dict[str, Union[str, List[Dict[str, str]]]] = {
"light_logo": "img/libtmux.svg",
"dark_logo": "img/libtmux.svg",
"footer_icons": [
Expand Down Expand Up @@ -162,7 +162,9 @@
intersphinx_mapping = {"http://docs.python.org/": None}


def linkcode_resolve(domain, info): # NOQA: C901
def linkcode_resolve(
domain: str, info: Dict[str, str]
) -> Union[None, str]: # NOQA: C901
"""
Determine the URL corresponding to Python object

Expand Down Expand Up @@ -195,7 +197,8 @@ def linkcode_resolve(domain, info): # NOQA: C901
except AttributeError:
pass
else:
obj = unwrap(obj)
if callable(obj):
obj = unwrap(obj)

try:
fn = inspect.getsourcefile(obj)
Expand Down
2 changes: 1 addition & 1 deletion libtmux/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
__title__ = "libtmux"
__package_name__ = "libtmux"
__version__ = "0.12.0"
__description__ = "Scripting library / ORM / API wrapper for tmux"
__description__ = "Typed scripting library / ORM / API wrapper for tmux"
__email__ = "tony@git-pull.com"
__author__ = "Tony Narlock"
__github__ = "https://github.com/tmux-python/libtmux"
Expand Down
8 changes: 7 additions & 1 deletion libtmux/_compat.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# flake8: NOQA
import sys
import types
import typing as t

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


# TODO Consider removing, reraise does not seem to be called anywhere
def reraise(tp, value, tb=None):
def reraise(
tp: t.Type[BaseException],
value: BaseException,
tb: types.TracebackType,
) -> t.NoReturn:

if value.__traceback__ is not tb:
raise (value.with_traceback(tb))
raise value
Expand Down
Loading