Skip to content

Commit 842f400

Browse files
stroxlerfacebook-github-bot
authored andcommitted
Infer: fully type tests
Summary: The existing `infer_test.py` was marked as pyre unsafe (many of our test modules are). This commit fully types the code, except for a bit of dict handling that is not easy to statically type. Reviewed By: pradeep90 Differential Revision: D28935759 fbshipit-source-id: 3683588cf2d8c93029feef6792b4f9b6b0a1fbd2
1 parent 89e1b9d commit 842f400

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

client/commands/tests/infer_v2_test.py

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

6-
# pyre-unsafe
76
from __future__ import annotations
87

98
import textwrap
@@ -25,18 +24,19 @@
2524

2625

2726
def _raw_infer_output(
28-
data: dict | None,
27+
data: dict[str, object] | None,
2928
) -> RawInferOutput:
3029
data = data or {}
3130
for category in RawInferOutput.categories:
3231
data[category] = data.get(category, [])
32+
# pyre-ignore[16]: Converting raw dicts to dataclasses.
3333
for annotation in data[category]:
3434
annotation["location"] = {"path": PATH}
3535
return RawInferOutput(data=cast(RawInferOutputDict, data))
3636

3737

3838
def _create_test_module_annotations(
39-
data: dict | None,
39+
data: dict[str, object] | None,
4040
complete_only: bool,
4141
) -> ModuleAnnotations:
4242
all_module_annotations = _create_module_annotations(
@@ -50,7 +50,7 @@ def _create_test_module_annotations(
5050
return module_annotations
5151

5252

53-
def _assert_stubs_equal(actual, expected):
53+
def _assert_stubs_equal(actual: str, expected: str) -> None:
5454
actual = actual.strip()
5555
expected = textwrap.dedent(expected.rstrip())
5656
if actual != expected:
@@ -62,7 +62,7 @@ def _assert_stubs_equal(actual, expected):
6262
class StubGenerationTest(unittest.TestCase):
6363
def _assert_stubs(
6464
self,
65-
data: dict,
65+
data: dict[str, object],
6666
expected: str,
6767
complete_only: bool = False,
6868
) -> None:
@@ -569,7 +569,9 @@ def with_params(y=7, x: List[int] = [5]) -> Union[int, str]: ...
569569

570570

571571
class ExistingAnnotationsTest(unittest.TestCase):
572-
def _assert_stubs(self, code: str, expected: str, data: dict | None = None) -> None:
572+
def _assert_stubs(
573+
self, code: str, expected: str, data: dict[str, object] | None = None
574+
) -> None:
573575
module_annotations = ModuleAnnotations.from_module(
574576
path=PATH, module=libcst.parse_module(textwrap.dedent(code))
575577
)

0 commit comments

Comments
 (0)