Skip to content

Commit a4260ec

Browse files
committed
Update some PYRE overrides
1 parent 58ad2c4 commit a4260ec

6 files changed

Lines changed: 24 additions & 17 deletions

File tree

examples/benchmark_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ def _warmup_executor(
197197
last_output: T | None = None
198198
for future in as_completed(futures):
199199
last_output = future.result()
200-
return last_output # pyre-ignore[7]
200+
assert last_output is not None
201+
return last_output
201202

202203

203204
class BenchmarkRunner:
@@ -282,7 +283,8 @@ def _run_iterations(
282283
qps_samples.append(iterations / elapsed)
283284
cpu_samples.append(cpu_percent / iterations)
284285

285-
return qps_samples, cpu_samples, last_output # pyre-ignore[7]
286+
assert last_output is not None
287+
return qps_samples, cpu_samples, last_output
286288

287289
def run(
288290
self,

src/spdl/_internal/import_utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# pyre-unsafe
7+
# pyre-strict
88

99
import importlib
10+
from collections.abc import Callable
1011
from types import ModuleType
12+
from typing import Any
1113

1214
__all__ = [
1315
"lazy_import",
@@ -17,28 +19,28 @@
1719
class _LazilyImportedModule(ModuleType):
1820
"""Delay module import until its attribute is accessed."""
1921

20-
def __init__(self, name, import_func):
22+
def __init__(self, name: str, import_func: Callable[[], ModuleType]) -> None:
2123
super().__init__(name)
2224
self.import_func = import_func
23-
self.module = None
25+
self.module: ModuleType | None = None
2426

2527
# Note:
2628
# Python caches what was retrieved with `__getattr__`, so this method will not be
2729
# called again for the same item.
28-
def __getattr__(self, item):
30+
def __getattr__(self, item: str) -> Any:
2931
self._import_once()
3032
return getattr(self.module, item)
3133

32-
def __repr__(self):
34+
def __repr__(self) -> str:
3335
if self.module is None:
3436
return f"<module '{self.__module__}.{self.__class__.__name__}(\"{self.__name__}\")'>"
3537
return repr(self.module)
3638

37-
def __dir__(self):
39+
def __dir__(self) -> list[str]:
3840
self._import_once()
3941
return dir(self.module)
4042

41-
def _import_once(self):
43+
def _import_once(self) -> None:
4244
if self.module is None:
4345
self.module = self.import_func()
4446
# Note:

tests/io/configs_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# pyre-unsafe
7+
# pyre-strict
88

99
import unittest
1010

tests/io/frames_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# pyre-unsafe
7+
# pyre-strict
88

99
import unittest
1010

tests/io/zero_copy_bytes_passing_test.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# pyre-unsafe
7+
# pyre-strict
88

99
import unittest
10+
from typing import Any
1011

1112
import numpy as np
1213
import spdl.io
14+
from numpy.typing import NDArray
1315

1416
from ..fixture import FFMPEG_CLI, get_sample
1517

1618

17-
def _decode(media_type, src):
19+
def _decode(media_type: str, src: str | bytes) -> NDArray[Any]:
1820
demux_func = {
1921
"audio": spdl.io.demux_audio,
2022
"video": spdl.io.demux_video,
2123
"image": spdl.io.demux_image,
2224
}[media_type]
2325

2426
packets = demux_func(src)
25-
frames = spdl.io.decode_packets(packets)
27+
frames = spdl.io.decode_packets(packets) # pyre-ignore[6]
2628
buffer = spdl.io.convert_frames(frames)
2729
return spdl.io.to_numpy(buffer)
2830

tests/pipeline/pipeline_failure_exceptstar_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# This source code is licensed under the BSD-style license found in the
55
# LICENSE file in the root directory of this source tree.
66

7-
# pyre-unsafe
7+
# pyre-strict
88

99
"""Tests for PipelineFailure using ``except*`` syntax (Python 3.11+ only).
1010
@@ -15,20 +15,21 @@
1515

1616
import sys
1717
import unittest
18+
from collections.abc import Iterator
1819

1920
if sys.version_info < (3, 11):
2021
raise unittest.SkipTest("except* syntax requires Python 3.11+")
2122

2223
from spdl.pipeline import PipelineBuilder
2324

2425

25-
def passthrough(x):
26+
def passthrough(x: int) -> int:
2627
return x
2728

2829

2930
class TestPipelineFailureExceptStar(unittest.TestCase):
3031
def test_pipeline_failure_except_star(self) -> None:
31-
def failing_range(n):
32+
def failing_range(n: int) -> Iterator[int]:
3233
yield from range(n)
3334
raise ValueError("Iterator failed")
3435

0 commit comments

Comments
 (0)