Skip to content

Commit a251768

Browse files
committed
improve type hints
This makes static analyzers happy.
1 parent 82e77f0 commit a251768

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ description = "Python wrapper for the mpy-cross tool from MicroPython."
99
readme = "README.md"
1010

1111
[project.scripts]
12-
"mpy-cross-v6.3" = "mpy_cross_v6_3:_run"
12+
"mpy-cross-v6.3" = "mpy_cross_v6_3:run"
1313

1414
[tool.setuptools.packages.find]
1515
where = ["src"]

src/mpy_cross_v6_3/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import List, Optional, Tuple
88

99

10-
MPY_CROSS_PATH = (
10+
MPY_CROSS_PATH = str(
1111
(pathlib.Path(__file__).parent / "mpy-cross")
1212
.with_suffix(".exe" if platform.system() == "Windows" else "")
1313
.absolute()
@@ -42,7 +42,7 @@ def mpy_cross_compile(
4242
emit: Optional[Emitter] = None,
4343
heap_size: Optional[int] = None,
4444
extra_args: Optional[List[str]] = None,
45-
) -> Tuple[subprocess.CompletedProcess, Optional[bytes]]:
45+
) -> Tuple[subprocess.CompletedProcess[bytes], Optional[bytes]]:
4646
"""
4747
Compiles a file using mpy-cross.
4848
@@ -75,13 +75,13 @@ def mpy_cross_compile(
7575
...
7676
7777
"""
78-
with tempfile.TemporaryDirectory() as tmp_dir:
79-
tmp_dir = pathlib.Path(tmp_dir)
78+
with tempfile.TemporaryDirectory() as tmp_dir_name:
79+
tmp_dir = pathlib.Path(tmp_dir_name)
8080

8181
with open(tmp_dir / "tmp.py", "w") as in_file:
8282
in_file.write(file_contents)
8383

84-
args = [MPY_CROSS_PATH, in_file.name, "-s", file_name]
84+
args: list[str] = [MPY_CROSS_PATH, in_file.name, "-s", file_name]
8585

8686
if optimization_level is not None:
8787
if optimization_level not in range(4):
@@ -124,7 +124,7 @@ def mpy_cross_version() -> str:
124124
return proc.stdout.decode().strip()
125125

126126

127-
def _run():
127+
def run() -> None:
128128
"""
129129
Run mpy-cross directly.
130130
"""

src/mpy_cross_v6_3/__main__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from . import _run
1+
from . import run
22

33
if __name__ == "__main__":
4-
_run()
4+
run()

tests/test_mpy_cross.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
def test_compile_no_opts():
77
p, mpy = mpy_cross_compile("test.py", "")
88
p.check_returncode()
9+
assert mpy is not None
910

1011
magic, version, flags, small_int_bits = struct.unpack_from("BBBB", mpy)
1112

@@ -18,6 +19,7 @@ def test_compile_no_opts():
1819
def test_compile_opt_small_int_bits():
1920
p, mpy = mpy_cross_compile("test.py", "", small_number_bits=63)
2021
p.check_returncode()
22+
assert mpy is not None
2123

2224
magic, version, flags, small_int_bits = struct.unpack_from("BBBB", mpy)
2325

0 commit comments

Comments
 (0)