|
1 | 1 | # SPDX-License-Identifier: MIT |
2 | | -# Copyright (c) 2022 The Pybricks Authors |
| 2 | +# Copyright (c) 2022-2026 The Pybricks Authors |
3 | 3 |
|
4 | 4 |
|
5 | 5 | import contextlib |
6 | 6 | import os |
7 | 7 | import struct |
8 | 8 | import sys |
9 | 9 | from tempfile import TemporaryDirectory |
| 10 | +from typing import Any |
10 | 11 |
|
11 | 12 | import pytest |
12 | 13 |
|
|
16 | 17 | if sys.version_info < (3, 11): |
17 | 18 | from contextlib import AbstractContextManager |
18 | 19 |
|
19 | | - class chdir(AbstractContextManager): |
| 20 | + class chdir(AbstractContextManager[None]): |
20 | 21 | """Non thread-safe context manager to change the current working directory.""" |
21 | 22 |
|
22 | | - def __init__(self, path): |
| 23 | + def __init__(self, path: str) -> None: |
23 | 24 | self.path = path |
24 | | - self._old_cwd = [] |
| 25 | + self._old_cwd: list[str] = [] |
25 | 26 |
|
26 | | - def __enter__(self): |
| 27 | + def __enter__(self) -> None: |
27 | 28 | self._old_cwd.append(os.getcwd()) |
28 | 29 | os.chdir(self.path) |
29 | 30 |
|
30 | | - def __exit__(self, *excinfo): |
| 31 | + def __exit__(self, *excinfo: Any) -> None: |
31 | 32 | os.chdir(self._old_cwd.pop()) |
32 | 33 |
|
33 | 34 | setattr(contextlib, "chdir", chdir) |
@@ -130,10 +131,12 @@ def unpack_mpy(data: bytes) -> tuple[bytes, bytes]: |
130 | 131 | names.add(name2.decode()) |
131 | 132 | name3, mpy3 = unpack_mpy(multi_mpy) |
132 | 133 | names.add(name3.decode()) |
| 134 | + |
133 | 135 | if uses_module_finder: |
134 | 136 | # ModuleFinder requires __init__.py. |
135 | 137 | name4, mpy4 = unpack_mpy(multi_mpy) |
136 | 138 | names.add(name4.decode()) |
| 139 | + |
137 | 140 | name5, mpy5 = unpack_mpy(multi_mpy) |
138 | 141 | names.add(name5.decode()) |
139 | 142 |
|
|
0 commit comments