[BE] Fix flake8 B027 errors - missing abstractmethod decorator (#100715)

Enables B027 and applies fixes by adding abstract method decorators. Autofix generated by ruff master.

Pull Request resolved: https://github.com/pytorch/pytorch/pull/100715
Approved by: https://github.com/ezyang
This commit is contained in:
Aaron Gokaslan
2023-05-09 17:24:14 +00:00
committed by PyTorch MergeBot
parent bd18225c04
commit 8769fb854d
13 changed files with 11 additions and 18 deletions

View File

@ -14,7 +14,7 @@ ignore =
# to line this up with executable bit
EXE001,
# these ignores are from flake8-bugbear; please fix!
B007,B008,B017,B019,B020,B023,B024,B026,B027,B028,B903,B904,B905,B906,B907
B007,B008,B017,B019,B020,B023,B024,B026,B028,B903,B904,B905,B906,B907
# these ignores are from flake8-comprehensions; please fix!
C407,
# these ignores are from flake8-logging-format; please fix!

View File

@ -999,6 +999,6 @@ init_command = [
'python3',
'tools/linter/adapters/pip_init.py',
'--dry-run={{DRYRUN}}',
'ruff==0.0.262',
'ruff==0.0.265',
]
is_formatter = true

View File

@ -17,9 +17,6 @@ class NetModifier(metaclass=abc.ABCMeta):
modifier(net)
"""
def __init__(self):
pass
@abc.abstractmethod
def modify_net(self, net, init_net=None, grad_map=None, blob_to_device=None):
pass

View File

@ -32,7 +32,7 @@ ignore = [
"B019", "B020",
"B023", "B024", "B026",
"B028", # No explicit `stacklevel` keyword argument found
"B027", "B904", "B905",
"B904", "B905",
"E402",
"C408", # C408 ignored because we like the dict keyword argument syntax
"E501", # E501 is not flexible enough, we're using B950 instead

View File

@ -3521,7 +3521,7 @@ def fn():
def test_user_function_variable_supports_type_abcmeta_argument(self):
class Foo(metaclass=abc.ABCMeta):
@abc.abstractclassmethod
def read(self):
def read(self): # noqa: B027
pass
class Bar(Foo):

View File

@ -23,6 +23,7 @@ __all__ = [
class FuseHandler(ABC):
""" Base handler class for the fusion patterns
"""
@abstractmethod
def __init__(self, node: Node):
pass

View File

@ -78,6 +78,7 @@ class _TensorLoader(ABC):
def add(self, size: int, obj: object):
pass
@abstractmethod
def start_loading(self):
pass

View File

@ -84,6 +84,7 @@ class _TensorLoader(ABC):
def add(self, size, obj):
pass
@abstractmethod
def start_loading(self):
pass

View File

@ -105,6 +105,7 @@ class RendezvousHandler(ABC):
allow nodes to join the correct distributed application.
"""
@abstractmethod
def shutdown(self) -> bool:
"""Closes all resources that were open for the rendezvous.

View File

@ -39,8 +39,6 @@ class _FSDPPolicy(ABC):
# The motivation for this abstract base class is to hide the interface
# expected by `_recursive_wrap()` from users (i.e. the `recurse` argument).
def __init__(self):
...
@property
@abstractmethod

View File

@ -31,9 +31,6 @@ class PassBase(abc.ABC):
the PassManager's `passes` attribute.
"""
def __init__(self) -> None:
pass
def __call__(self, graph_module: GraphModule) -> Optional[PassResult]:
"""
Runs the precondition check, the pass itself, and the postcondition check.
@ -55,7 +52,7 @@ class PassBase(abc.ABC):
"""
pass
def requires(self, graph_module: GraphModule) -> None:
def requires(self, graph_module: GraphModule) -> None: # noqa: B027
"""
This function will be called before the pass is run and will check that
the given graph module contains the preconditions needed to run the
@ -66,7 +63,7 @@ class PassBase(abc.ABC):
"""
pass
def ensures(self, graph_module: GraphModule) -> None:
def ensures(self, graph_module: GraphModule) -> None: # noqa: B027
"""
This function will be called after the pass is run and will check that
the given graph module contains the postconditions needed to run the

View File

@ -17,9 +17,6 @@ class BasePruningMethod(ABC):
"""
_tensor_name: str
def __init__(self):
pass
def __call__(self, module, inputs):
r"""Multiplies the mask (stored in ``module[name + '_mask']``)
into the original tensor (stored in ``module[name + '_orig']``)

View File

@ -35,7 +35,7 @@ class RpcAgentTestFixture(ABC):
def rpc_backend_options(self):
pass
def setup_fault_injection(self, faulty_messages, messages_to_delay):
def setup_fault_injection(self, faulty_messages, messages_to_delay): # noqa: B027
"""Method used by dist_init to prepare the faulty agent.
Does nothing for other agents.