Skip to content

Commit cac2835

Browse files
committed
Update Mypy config.
Migrate to pyproject.toml. Add types-cffi stubs.
1 parent a828e13 commit cac2835

5 files changed

Lines changed: 43 additions & 8 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
uses: liskin/gh-problem-matcher-wrap@v2
7070
with:
7171
linters: mypy
72-
run: mypy --show-column-numbers .
72+
run: mypy --show-column-numbers
7373

7474
# This makes sure that the latest versions of the SDL headers parse correctly.
7575
parse_sdl:

build_libtcod.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pathlib import Path
1010
from typing import Any, Dict, Iterable, Iterator, List, Set, Tuple, Union
1111

12-
from cffi import FFI # type: ignore
12+
from cffi import FFI
1313

1414
sys.path.append(str(Path(__file__).parent)) # Allow importing local modules.
1515

pyproject.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,39 @@ filterwarnings = [
101101
"ignore:This class may perform poorly and is no longer needed.::tcod.map",
102102
]
103103

104+
[tool.mypy]
105+
files = ["."]
106+
python_version = 3.8
107+
warn_unused_configs = true
108+
show_error_codes = true
109+
disallow_subclassing_any = true
110+
disallow_any_generics = true
111+
disallow_untyped_calls = true
112+
disallow_untyped_defs = true
113+
disallow_incomplete_defs = true
114+
check_untyped_defs = true
115+
disallow_untyped_decorators = true
116+
no_implicit_optional = true
117+
warn_redundant_casts = true
118+
warn_unused_ignores = true
119+
warn_return_any = true
120+
implicit_reexport = false
121+
strict_equality = true
122+
exclude = [
123+
"build/",
124+
"venv/",
125+
"libtcod/",
126+
"docs/",
127+
"distribution/",
128+
"termbox/",
129+
"samples_libtcodpy.py",
130+
]
131+
132+
[[tool.mypy.overrides]]
133+
module = "numpy.*"
134+
ignore_missing_imports = true
135+
136+
104137
[tool.ruff]
105138
# https://beta.ruff.rs/docs/rules/
106139
select = [

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ numpy>=1.21.4
33
pycparser>=2.14
44
requests>=2.28.1
55
setuptools==65.5.1
6+
types-cffi
67
types-requests
78
types-setuptools
89
types-tabulate

tcod/loader.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from pathlib import Path
88
from typing import Any # noqa: F401
99

10-
import cffi # type: ignore
10+
import cffi
1111

1212
__sdl_version__ = ""
1313

@@ -29,12 +29,13 @@
2929
def verify_dependencies() -> None:
3030
"""Try to make sure dependencies exist on this system."""
3131
if sys.platform == "win32":
32-
lib_test = ffi_check.dlopen("SDL2.dll") # Make sure SDL2.dll is here.
33-
version = ffi_check.new("struct SDL_version*")
32+
lib_test: Any = ffi_check.dlopen("SDL2.dll") # Make sure SDL2.dll is here.
33+
version: Any = ffi_check.new("struct SDL_version*")
3434
lib_test.SDL_GetVersion(version) # Need to check this version.
35-
version = version.major, version.minor, version.patch
36-
if version < (2, 0, 5):
37-
raise RuntimeError("Tried to load an old version of SDL %r" % (version,))
35+
version_tuple = version.major, version.minor, version.patch
36+
if version_tuple < (2, 0, 5):
37+
msg = f"Tried to load an old version of SDL {version_tuple!r}"
38+
raise RuntimeError(msg)
3839

3940

4041
def get_architecture() -> str:

0 commit comments

Comments
 (0)