Skip to content

Commit

Permalink
[BE]: Enable ruff rules PIE807 and PIE810 (pytorch#106218)
Browse files Browse the repository at this point in the history
* 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: pytorch#106218
Approved by: https://github.com/albanD
  • Loading branch information
Skylion007 authored and pytorchmergebot committed Jul 28, 2023
1 parent f3d165b commit 52d4b1a
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/scripts/gitutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ select = [
"UP",
"PERF",
"PGH004",
"PIE807",
"PIE810",
"PLE",
"TRY302",
]
Expand Down
2 changes: 1 addition & 1 deletion torch/_export/db/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions torchgen/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 52d4b1a

Please sign in to comment.