Skip to content

Commit ef2384a

Browse files
yangdanny97facebook-github-bot
authored andcommitted
clean up pyre-fixmes
Summary: The bulk of these were enum annotation issues from the quality insights dashboard. There were also pyre errors caused by shadowing/redeclaring variables, which came up in the discussion re: Pyrefly and Pytorch. The enum issues are fixed via codemod, by running ``` buck2 run fbcode//tools/pyre/facebook/tools/codemods:codemods -- enum_annotations <file name> ``` Reviewed By: stroxler Differential Revision: D74484869 fbshipit-source-id: dedea875173cd2dcdbab8c90ab6d16e3234776d5
1 parent 2baa01d commit ef2384a

File tree

10 files changed

+51
-73
lines changed

10 files changed

+51
-73
lines changed

client/command_arguments.py

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,14 @@
3838

3939

4040
class ProfileOutput(enum.Enum):
41-
# pyre-fixme[35]: Target cannot be annotated.
42-
TRACE_EVENT: str = "trace_event"
43-
# pyre-fixme[35]: Target cannot be annotated.
44-
COLD_START_PHASES: str = "cold_start_phases"
45-
# pyre-fixme[35]: Target cannot be annotated.
46-
INCREMENTAL_UPDATES: str = "incremental_updates"
47-
# pyre-fixme[35]: Target cannot be annotated.
48-
TAINT: str = "taint"
49-
# pyre-fixme[35]: Target cannot be annotated.
50-
INDIVIDUAL_TABLE_SIZES: str = "individual_table_sizes"
51-
# pyre-fixme[35]: Target cannot be annotated.
52-
TOTAL_SHARED_MEMORY_SIZE_OVER_TIME: str = "total_shared_memory_size_over_time"
53-
# pyre-fixme[35]: Target cannot be annotated.
54-
TOTAL_SHARED_MEMORY_SIZE_OVER_TIME_GRAPH: str = (
41+
_value_: str
42+
TRACE_EVENT = "trace_event"
43+
COLD_START_PHASES = "cold_start_phases"
44+
INCREMENTAL_UPDATES = "incremental_updates"
45+
TAINT = "taint"
46+
INDIVIDUAL_TABLE_SIZES = "individual_table_sizes"
47+
TOTAL_SHARED_MEMORY_SIZE_OVER_TIME = "total_shared_memory_size_over_time"
48+
TOTAL_SHARED_MEMORY_SIZE_OVER_TIME_GRAPH = (
5549
"total_shared_memory_size_over_time_graph" # noqa B950
5650
)
5751

@@ -60,26 +54,22 @@ def __str__(self) -> str:
6054

6155

6256
class VersionKind(str, enum.Enum):
63-
# pyre-fixme[35]: Target cannot be annotated.
64-
NONE: str = "none"
65-
# pyre-fixme[35]: Target cannot be annotated.
66-
CLIENT: str = "client"
67-
# pyre-fixme[35]: Target cannot be annotated.
68-
CLIENT_AND_BINARY: str = "client_and_binary"
57+
_value_: str
58+
NONE = "none"
59+
CLIENT = "client"
60+
CLIENT_AND_BINARY = "client_and_binary"
6961

7062

7163
class MissingFlowsKind(str, enum.Enum):
72-
# pyre-fixme[35]: Target cannot be annotated.
73-
OBSCURE: str = "obscure"
74-
# pyre-fixme[35]: Target cannot be annotated.
75-
TYPE: str = "type"
64+
_value_: str
65+
OBSCURE = "obscure"
66+
TYPE = "type"
7667

7768

7869
class TaintOutputFormat(str, enum.Enum):
79-
# pyre-fixme[35]: Target cannot be annotated.
80-
JSON: str = "json"
81-
# pyre-fixme[35]: Target cannot be annotated.
82-
SHARDED_JSON: str = "sharded-json"
70+
_value_: str
71+
JSON = "json"
72+
SHARDED_JSON = "sharded-json"
8373

8474

8575
@dataclass(frozen=True)

client/commands/incremental.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,9 @@ class InvalidServerResponse(Exception):
4848

4949

5050
class ServerStatus(str, enum.Enum):
51-
# pyre-fixme[35]: Target cannot be annotated.
52-
NEWLY_STARTED: str = "newly_started_server"
53-
# pyre-fixme[35]: Target cannot be annotated.
54-
ALREADY_RUNNING: str = "already_running_server"
51+
_value_: str
52+
NEWLY_STARTED = "newly_started_server"
53+
ALREADY_RUNNING = "already_running_server"
5554

5655
def __str__(self) -> str:
5756
return self.value

client/configuration/site_packages.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,10 @@
2929

3030

3131
class SearchStrategy(str, enum.Enum):
32-
# pyre-fixme[35]: Target cannot be annotated.
33-
NONE: str = "none"
34-
# pyre-fixme[35]: Target cannot be annotated.
35-
ALL: str = "all"
36-
# pyre-fixme[35]: Target cannot be annotated.
37-
PEP561: str = "pep561"
32+
_value_: str
33+
NONE = "none"
34+
ALL = "all"
35+
PEP561 = "pep561"
3836

3937
def __str__(self) -> str:
4038
return self.value
@@ -48,12 +46,10 @@ def from_string(input: str) -> "Optional[SearchStrategy]":
4846

4947

5048
class PackageStatus(enum.IntEnum):
51-
# pyre-fixme[35]: Target cannot be annotated.
52-
UNTYPED: int = 0
53-
# pyre-fixme[35]: Target cannot be annotated.
54-
PARTIALLY_TYPED: int = 1
55-
# pyre-fixme[35]: Target cannot be annotated.
56-
TYPED: int = 2
49+
_value_: int
50+
UNTYPED = 0
51+
PARTIALLY_TYPED = 1
52+
TYPED = 2
5753

5854

5955
@dataclasses.dataclass(frozen=True)

client/dataclasses_merge.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ class Baz:
103103

104104

105105
class Policy(str, enum.Enum):
106-
# pyre-fixme[35]: Target cannot be annotated.
107-
OVERWRITE: str = "overwrite"
108-
# pyre-fixme[35]: Target cannot be annotated.
109-
PREPEND: str = "prepend"
110-
# pyre-fixme[35]: Target cannot be annotated.
111-
RAISE_WHEN_OVERWRITTEN: str = "raise_when_overwritten"
106+
_value_: str
107+
OVERWRITE = "overwrite"
108+
PREPEND = "prepend"
109+
RAISE_WHEN_OVERWRITTEN = "raise_when_overwritten"
112110

113111

114112
class DataclassMergeError(Exception):

scripts/pypi/build_pypi_package.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@ def _run_setup_command(
278278
package_name="pyre-check-nightly" if nightly else "pyre-check",
279279
package_version=version,
280280
module_name=MODULE_NAME,
281-
# pyre-fixme[6]: Expected `List[str]` for 4th param but got `Sequence[str]`.
282281
runtime_dependencies=dependencies,
283282
long_description=long_description,
284283
script_name="setup.py",

scripts/pypi/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
import os
1515
import sys
1616
from pathlib import Path
17-
from typing import List, Tuple
17+
from typing import List, Sequence, Tuple
1818

1919
from setuptools import find_packages, setup
2020

@@ -77,7 +77,7 @@ def run(
7777
package_name: str,
7878
package_version: str,
7979
module_name: str,
80-
runtime_dependencies: List[str],
80+
runtime_dependencies: Sequence[str],
8181
long_description: str,
8282
**kwargs: object,
8383
) -> None:

tools/generate_taint_models/decorator_parser.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ def _parse_decorator(
9090
argument.s for argument in decorator.args if isinstance(argument, ast.Str)
9191
}
9292
decorator_keywords = {
93-
# pyre-fixme[22]: The cast is redundant.
94-
(keyword.arg, cast(ast.Str, keyword.value).s)
93+
(keyword.arg, keyword.value.s)
9594
for keyword in decorator.keywords
9695
if isinstance(keyword.value, ast.Str)
9796
}

tools/typeshed_patcher/patch_specs.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ def is_empty(self) -> bool:
6262

6363

6464
class AddPosition(str, enum.Enum):
65-
# pyre-fixme[35]: Target cannot be annotated.
66-
TOP_OF_SCOPE: str = "top"
67-
# pyre-fixme[35]: Target cannot be annotated.
68-
BOTTOM_OF_SCOPE: str = "bottom"
65+
_value_: str
66+
TOP_OF_SCOPE = "top"
67+
BOTTOM_OF_SCOPE = "bottom"
6968

7069
@staticmethod
7170
def from_json(input_object: object) -> "AddPosition":

tools/upgrade/commands/codemods.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ def add_arguments(cls, parser: argparse.ArgumentParser) -> None:
5555
@override
5656
def run(self) -> None:
5757
errors = Errors.from_stdin(self._only_fix_error_code)
58-
# pyre-fixme[16]: `List` has no attribute `paths_to_errors`.
59-
for path, errors in errors.paths_to_errors.items():
58+
for path, errors_for_path in errors.paths_to_errors.items():
6059
LOG.info("Patching errors in `%s`.", path)
61-
errors = sorted(errors, key=lambda error: error["line"], reverse=True)
60+
errors_for_path = sorted(
61+
errors_for_path, key=lambda error: error["line"], reverse=True
62+
)
6263

6364
path = pathlib.Path(path)
6465
lines = path.read_text().split("\n")
6566

66-
for error in errors:
67+
for error in errors_for_path:
6768
if error["code"] != 15:
6869
continue
6970
line = error["line"] - 1
@@ -114,15 +115,16 @@ def add_arguments(cls, parser: argparse.ArgumentParser) -> None:
114115
@override
115116
def run(self) -> None:
116117
errors = Errors.from_stdin(self._only_fix_error_code)
117-
# pyre-fixme[16]: `List` has no attribute `paths_to_errors`.
118-
for path, errors in errors.paths_to_errors.items():
118+
for path, errors_for_path in errors.paths_to_errors.items():
119119
LOG.info("Patching errors in `%s`", path)
120-
errors = sorted(errors, key=lambda error: error["line"], reverse=True)
120+
errors_for_path = sorted(
121+
errors_for_path, key=lambda error: error["line"], reverse=True
122+
)
121123

122124
path = pathlib.Path(path)
123125
lines = path.read_text().split("\n")
124126

125-
for error in errors:
127+
for error in errors_for_path:
126128
if error["code"] != 5:
127129
continue
128130

tools/upgrade/commands/targets_to_configuration.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,14 +186,10 @@ def find_or_create_configuration(
186186

187187
def collect_full_targets(self, targets: Dict[str, List[Target]]) -> List[str]:
188188
new_targets = []
189-
# pyre-fixme[9]: targets has type `Dict[str, List[Target]]`; used as
190-
# `List[Target]`.
191-
for path, targets in targets.items():
189+
for path, targets_for_path in targets.items():
192190
new_targets += [
193-
# pyre-fixme[16]: `str` has no attribute `name`.
194191
"//" + path.replace("/TARGETS", "") + ":" + target.name
195-
for target in targets
196-
# pyre-fixme[16]: `str` has no attribute `check_types`.
192+
for target in targets_for_path
197193
if target.check_types
198194
]
199195
return new_targets

0 commit comments

Comments
 (0)