[BE]: Enable ruff rules PIE807 and PIE810 (#106218)

* Enables PIE807 + PIE810. PIE807 is do not reimplement list builtin function using lambda and PIE810 is to always fuse startswith / endswith calls (I applied the autofixes for this before we had ruff enabled).
Pull Request resolved: https://github.com/pytorch/pytorch/pull/106218
Approved by: https://github.com/albanD
This commit is contained in:
Aaron Gokaslan
2023-07-28 22:35:53 +00:00
committed by PyTorch MergeBot
parent f3d165bf61
commit 52d4b1ae31
4 changed files with 6 additions and 4 deletions

View File

@ -38,7 +38,7 @@ def fuzzy_list_to_dict(items: List[Tuple[str, str]]) -> Dict[str, List[str]]:
"""
Converts list to dict preserving elements with duplicate keys
"""
rc: Dict[str, List[str]] = defaultdict(lambda: [])
rc: Dict[str, List[str]] = defaultdict(list)
for key, val in items:
rc[key].append(val)
return dict(rc)

View File

@ -71,6 +71,8 @@ select = [
"UP",
"PERF",
"PGH004",
"PIE807",
"PIE810",
"PLE",
"TRY302",
]

View File

@ -78,7 +78,7 @@ class ExportCase:
# Tags associated with the use case. (e.g dynamic-shape, escape-hatch)
tags: Set[str] = field(default_factory=lambda: set())
support_level: SupportLevel = SupportLevel.SUPPORTED
constraints: List[Constraint] = field(default_factory=lambda: [])
constraints: List[Constraint] = field(default_factory=list)
def __post_init__(self):
check_inputs_type(self.example_inputs)

View File

@ -1846,13 +1846,13 @@ def gen_per_operator_headers(
) -> None:
# For CMake builds, split operator declarations into separate headers in
# the ATen/ops folder to split up header dependencies
functions_by_root_name: Dict[str, List[NativeFunction]] = defaultdict(lambda: [])
functions_by_root_name: Dict[str, List[NativeFunction]] = defaultdict(list)
for fn in native_functions:
functions_by_root_name[fn.root_name].append(fn)
grouped_functions_by_root_name: Dict[
str, List[Union[NativeFunction, NativeFunctionsGroup]]
] = defaultdict(lambda: [])
] = defaultdict(list)
for group in grouped_native_functions:
name = group.root_name
grouped_functions_by_root_name[name].append(group)