Skip to content

Commit fa41884

Browse files
authored
Merge pull request #235 from jorenham/static-typing
2 parents 8ad2b16 + aa2f050 commit fa41884

File tree

11 files changed

+556
-256
lines changed

11 files changed

+556
-256
lines changed

.coveragerc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ exclude_lines =
55
def __repr__
66
if self.debug:
77
if settings.DEBUG
8+
if TYPE_CHECKING:
89
raise AssertionError
910
raise NotImplementedError
1011
if 0:
1112
if __name__ == .__main__.:
13+
@overload
1214

1315
[run]
14-
source = stl
16+
source = stl
1517
branch = True
16-

.github/workflows/type_check.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Type-check
2+
3+
on:
4+
push:
5+
branches: [master, develop]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
concurrency:
10+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
11+
cancel-in-progress: true
12+
13+
jobs:
14+
type-check:
15+
runs-on: ubuntu-latest
16+
timeout-minutes: 5
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- uses: astral-sh/setup-uv@v7
21+
with:
22+
activate-environment: true
23+
24+
- name: install
25+
run: uv pip install cython basedpyright pyrefly mypy .
26+
27+
- name: run basedpyright
28+
run: basedpyright
29+
30+
- name: run basedpyright --verifytypes
31+
run: basedpyright --ignoreexternal --verifytypes stl
32+
33+
- name: run pyrefly check
34+
run: pyrefly check
35+
36+
- name: run mypy
37+
run: mypy --no-incremental --cache-dir=/dev/null stl

pyproject.toml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
[tool.mypy]
2+
packages = ["stl"]
3+
local_partial_types = true
4+
allow_redefinition_new = true
5+
strict = true
6+
enable_error_code = [
7+
"exhaustive-match",
8+
"ignore-without-code",
9+
"redundant-expr",
10+
"truthy-bool",
11+
]
12+
warn_return_any = false
13+
14+
15+
[tool.pyright]
16+
pythonPlatform = "All"
17+
include = ["stl"]
18+
ignore = [".venv"]
19+
stubPath = "."
20+
typeCheckingMode = "strict"
21+
reportPrivateUsage = false # dupe of PLC2701
22+
reportUnusedParameter = false # dupe of F841
23+
reportUnusedVariable = false # dupe of F841
24+
25+
26+
[tool.pyrefly]
27+
project-includes = ["stl"]

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ def run(self):
123123
'Programming Language :: Python :: 3.12',
124124
'Programming Language :: Python :: 3.13',
125125
'Topic :: Software Development :: Libraries :: Python Modules',
126+
'Typing :: Typed',
126127
],
127128
install_requires=install_requires,
128129
cmdclass=dict(

stl/__about__.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
__package_name__ = 'numpy-stl'
2-
__import_name__ = 'stl'
3-
__version__ = '3.2.0'
4-
__author__ = 'Rick van Hattem'
5-
__author_email__ = '[email protected]'
6-
__description__ = ' '.join(
1+
from typing import Final
2+
3+
__package_name__: Final[str] = 'numpy-stl'
4+
__import_name__: Final[str] = 'stl'
5+
__version__: Final[str] = '3.2.0'
6+
__author__: Final[str] = 'Rick van Hattem'
7+
__author_email__: Final[str] = '[email protected]'
8+
__description__: Final[str] = ' '.join(
79
"""
810
Library to make reading, writing and modifying both binary and ascii STL files
911
easy.
1012
""".split()
1113
)
12-
__url__ = 'https://github.com/WoLpH/numpy-stl/'
14+
__url__: Final[str] = 'https://github.com/WoLpH/numpy-stl/'

stl/_speedups.pyi

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from typing import IO
2+
3+
import numpy as np
4+
from typing_extensions import Buffer, TypeAlias
5+
6+
_DataArray: TypeAlias = np.ndarray[tuple[int], np.dtype[np.void]]
7+
8+
def ascii_read(fh: IO[bytes], buf: Buffer) -> tuple[bytes, _DataArray]: ...
9+
def ascii_write(fh: IO[bytes], name: bytes, data: _DataArray) -> None: ...

0 commit comments

Comments
 (0)