[BE] Enable Ruff's Flake8 PYI045 (#111184)

Enable [iter-method-return-iterable (PYI045)](https://docs.astral.sh/ruff/rules/iter-method-return-iterable/#iter-method-return-iterable-pyi045)

Link: #110950
Pull Request resolved: https://github.com/pytorch/pytorch/pull/111184
Approved by: https://github.com/Skylion007
This commit is contained in:
isdanni
2023-10-13 22:20:00 +00:00
committed by PyTorch MergeBot
parent ba7b9211ee
commit 00d962631c
3 changed files with 4 additions and 5 deletions

View File

@ -51,7 +51,6 @@ ignore = [
"PYI024",
"PYI036",
"PYI041",
"PYI045",
"PYI056",
"SIM102", "SIM103", "SIM112", # flake8-simplify code styles
"SIM105", # these ignores are from flake8-simplify. please fix or ignore with commented reason

View File

@ -6,7 +6,7 @@
# LICENSE file in the root directory of this source tree.
"""The Pipe interface."""
from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Iterable, List, Optional, Union, Sequence, Tuple, cast
from typing import TYPE_CHECKING, Any, Iterable, Iterator, List, Optional, Union, Sequence, Tuple, cast
import torch
from torch import Tensor, nn
@ -379,7 +379,7 @@ class Pipe(Module):
raise IndexError
def __iter__(self) -> Iterable[nn.Module]:
def __iter__(self) -> Iterator[nn.Module]:
"""Iterates over children of the underlying sequential module."""
for partition in self.partitions:
yield from partition

View File

@ -12,7 +12,7 @@ from dataclasses import is_dataclass, fields
from .graph import magic_methods, reflectable_magic_methods, Graph
from typing import Tuple, Dict, OrderedDict, Optional, Iterable, Any, Iterator, Callable
from typing import Tuple, Dict, OrderedDict, Optional, Any, Iterator, Callable
from .node import Target, Node, Argument, base_types, map_aggregate
from ._compatibility import compatibility
from .operator_schemas import check_for_mutable_operation
@ -392,7 +392,7 @@ class Proxy:
def __call__(self, *args, **kwargs) -> 'Proxy':
return self.tracer.create_proxy('call_method', '__call__', (self,) + args, kwargs)
def __iter__(self) -> Iterable['Proxy']:
def __iter__(self) -> Iterator['Proxy']:
frame = inspect.currentframe()
assert frame is not None
calling_frame = frame.f_back