Skip to content

Commit 38e8b36

Browse files
yangdanny97facebook-github-bot
authored andcommitted
upgrade some of our files to pyre-strict
Summary: Added pyre-strict to some files from the code quality dashboard based on this devmate prompt: ``` Given the following list of files, if it contains the comment `# pyre-unsafe`, replace it with `# pyre-strict` 1. fbcode/tools/pyre/tools/generate\_taint\_models/tests/test\_functions.py 2. fbcode/tools/pyre/client/tests/json\_rpc\_test.py 3. fbcode/tools/pyre/tools/upgrade/tests/errors\_test.py 4. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_class\_sources\_test.py 5. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_graphql\_sources\_test.py 6. fbcode/tools/pyre/tools/upgrade/commands/tests/pysa\_version\_update\_test.py 7. fbcode/tools/pyre/scripts/run\_server\_integration\_test.py 8. fbcode/tools/pyre/tools/upgrade/commands/tests/expand\_target\_coverage\_test.py 9. fbcode/tools/pyre/facebook/tools/codemods/**tests**/add\_none\_test.py 10. fbcode/tools/pyre/facebook/client/commands/notify\_update.py 11. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_request\_specific\_data\_test.py 12. fbcode/tools/pyre/facebook/tools/codemods/**tests**/enum\_annotation\_test.py 13. fbcode/tools/pyre/tools/upgrade/commands/tests/fixme\_all\_test.py 14. fbcode/tools/pyre/facebook/pysa/fbcode\_tests/verify\_models\_test/test.py 15. fbcode/tools/pyre/tools/upgrade/commands/tests/consolidate\_nested\_configurations\_test.py 16. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_dynamic\_graphql\_sources\_test.py 17. fbcode/tools/pyre/pyre\_extensions/tests/safe\_json\_test.py 18. fbcode/tools/pyre/facebook/scripts/binary\_version\_manifold\_health\_helper.py 19. fbcode/tools/pyre/tools/upgrade/filesystem.py 20. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_globals\_test.py 21. fbcode/tools/pyre/pyre\_extensions/**init**.py 22. fbcode/tools/pyre/client/tests/terminal\_test.py 23. fbcode/tools/pyre/facebook/tools/codemods/**tests**/nd\_array\_test.py 24. fbcode/tools/pyre/facebook/tools/codemods/examples/add\_none\_example.py 25. fbcode/tools/pyre/tools/upgrade/commands/tests/global\_version\_update\_test.py 26. fbcode/tools/pyre/tools/upgrade/commands/tests/strict\_default\_test.py 27. fbcode/tools/pyre/client/commands/tests/statistics\_test.py 28. fbcode/tools/pyre/pyre\_extensions/tests/basic\_test.py 29. fbcode/tools/pyre/facebook/tools/migrations/per\_target/repository.py 30. fbcode/tools/pyre/facebook/client/tests/arguments\_adder\_test.py 31. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_REST\_api\_sources\_test.py 32. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_filtered\_sources\_test.py 33. fbcode/tools/pyre/tools/upgrade/commands/tests/command\_test.py 34. fbcode/tools/pyre/client/commands/tests/initialize\_test.py 35. fbcode/tools/pyre/client/tests/error\_test.py 36. fbcode/tools/pyre/client/tests/find\_directories\_test.py 37. fbcode/tools/pyre/pyre\_extensions/type\_variable\_operators.py 38. fbcode/tools/pyre/tools/generate\_taint\_models/tests/get\_exit\_nodes\_test.py 39. fbcode/tools/pyre/tools/upgrade/commands/tests/targets\_to\_configuration\_test.py 40. fbcode/tools/pyre/pyre\_extensions/generic.py 41. fbcode/tools/pyre/tools/upgrade/tests/upgrade\_test.py 42. fbcode/tools/pyre/tools/upgrade/commands/tests/fixme\_test.py 43. fbcode/tools/pyre/tools/upgrade/commands/tests/fix\_configuration\_test.py 44. fbcode/tools/pyre/facebook/conformance/conformance\_output.py ``` Then, I ran arc pyre check-changed-targets and reverted the ones that had issues with mock.patch. Some files were green without any changes, others required some small manual type annotation additions. Reviewed By: MaggieMoss Differential Revision: D74421675 fbshipit-source-id: 81734c932c54c0741f7f33b5e96ef287d001e095
1 parent cb31d33 commit 38e8b36

13 files changed

+23
-23
lines changed

client/tests/find_directories_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import subprocess
99
import tempfile
@@ -491,7 +491,7 @@ def test_find_global_and_local_root(self) -> None:
491491
class FindTypeshedTest(testslide.TestCase):
492492
def assert_typeshed_roots(
493493
self, relative_directories: Iterable[str], expected_roots: Iterable[str]
494-
):
494+
) -> None:
495495
self.maxDiff = None
496496
with tempfile.TemporaryDirectory() as root:
497497
root_path = Path(root)

client/tests/json_rpc_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import json
99
import unittest

client/tests/terminal_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99
from unittest.mock import MagicMock, patch

pyre_extensions/type_variable_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77
from typing import Any, Generic, TypeVar
88

99
from .generic import GenericMeta

scripts/run_server_integration_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
```
2020
"""
2121

22-
# pyre-unsafe
22+
# pyre-strict
2323

2424
import argparse
2525
import filecmp
@@ -34,7 +34,7 @@
3434
from argparse import Namespace
3535
from contextlib import contextmanager
3636
from logging import Logger
37-
from typing import Generator, Optional, Tuple
37+
from typing import Generator, Iterator, Optional, Tuple
3838

3939
LOG: Logger = logging.getLogger(__name__)
4040

@@ -119,15 +119,15 @@ def __init__(
119119
) -> None:
120120
# Parse list of fake commits.
121121
assert_readable_directory(repository_path)
122-
self._base_repository_path = os.path.realpath(repository_path)
122+
self._base_repository_path: str = os.path.realpath(repository_path)
123123
commits_list = os.listdir(self._base_repository_path)
124124
list.sort(commits_list)
125125
for commit in commits_list:
126126
assert_readable_directory(os.path.join(self._base_repository_path, commit))
127-
self._commits_list = iter(commits_list)
127+
self._commits_list: Iterator[str] = iter(commits_list)
128128

129129
# Move into the temporary repository directory.
130-
self._pyre_directory = os.path.join(base_directory, "repository")
130+
self._pyre_directory: str = os.path.join(base_directory, "repository")
131131
os.mkdir(self._pyre_directory)
132132
os.chdir(self._pyre_directory)
133133

@@ -318,7 +318,7 @@ def run_saved_state_test(
318318

319319

320320
@contextmanager
321-
def _watch_directory(source_directory) -> Generator[None, None, None]:
321+
def _watch_directory(source_directory: str) -> Generator[None, None, None]:
322322
subprocess.check_call(
323323
["watchman", "watch", source_directory],
324324
stdout=subprocess.DEVNULL,

tools/generate_taint_models/tests/get_REST_api_sources_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99
from unittest.mock import MagicMock

tools/generate_taint_models/tests/get_class_sources_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99

tools/generate_taint_models/tests/get_exit_nodes_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99
from unittest.mock import MagicMock

tools/generate_taint_models/tests/get_graphql_sources_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
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
6+
# pyre-strict
7+
78

8-
import os # noqa
99
import unittest
10-
from typing import Callable
1110

1211
from graphql3 import (
1312
GraphQLBoolean,
1413
GraphQLField,
14+
GraphQLFieldResolver,
1515
GraphQLID,
1616
GraphQLNonNull,
1717
GraphQLObjectType,
@@ -92,13 +92,13 @@ def function_2() -> None:
9292
)
9393

9494

95-
def add_field(type: GraphQLType, name: str, resolve: Callable) -> None:
95+
def add_field(type: GraphQLType, name: str, resolve: GraphQLFieldResolver | None) -> None:
9696
# pyre-ignore[16]: Undefined attribute
9797
type._fields[name] = GraphQLField(GraphQLNonNull(GraphQLID), resolve=resolve)
9898

9999

100100
# Indirectly add in an additional resolver, so that
101101
# 'test_gather_functions_to_model' can verify that that resolver is detected
102-
IndirectObjectType = add_field(
102+
IndirectObjectType: None = add_field(
103103
type=DirectObjectType, name="indirect", resolve=function_2
104104
)

tools/generate_taint_models/tests/get_request_specific_data_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99
from unittest.mock import MagicMock

tools/upgrade/commands/tests/fixme_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99
from unittest.mock import MagicMock, patch

tools/upgrade/filesystem.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
"""
99
TODO(T132414938) Add a module-level docstring

tools/upgrade/tests/upgrade_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
6+
# pyre-strict
77

88
import unittest
99

0 commit comments

Comments
 (0)