diff --git a/.flake8 b/.flake8 index 3f8cdcc4c541..2fcff14109b5 100644 --- a/.flake8 +++ b/.flake8 @@ -1,5 +1,6 @@ [flake8] -select = B,C,E,F,P,T4,W,B9 +enable-extensions = G +select = B,C,E,F,G,P,T4,W,B9 max-line-length = 120 # C408 ignored because we like the dict keyword argument syntax # E501 is not flexible enough, we're using B950 instead @@ -12,6 +13,8 @@ ignore = B007,B008, # these ignores are from flake8-comprehensions; please fix! C407 + # these ignores are from flake8-logging-format; please fix! + G001,G002,G003,G004,G100,G101,G200,G201,G202 per-file-ignores = __init__.py: F401 torch/utils/cpp_extension.py: B950 diff --git a/.lintrunner.toml b/.lintrunner.toml index 8782a8c26e71..33dc982d90bf 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -35,6 +35,7 @@ init_command = [ 'flake8-bugbear==20.1.4', 'flake8-comprehensions==3.3.0', 'flake8-executable==2.0.4', + 'flake8-logging-format==0.9.0', 'flake8-pyi==20.5.0', 'mccabe==0.6.1', 'pycodestyle==2.6.0', diff --git a/requirements-flake8.txt b/requirements-flake8.txt index 08c432ad4eb3..6824da33c759 100644 --- a/requirements-flake8.txt +++ b/requirements-flake8.txt @@ -2,6 +2,7 @@ flake8==3.8.2 flake8-bugbear==20.1.4 flake8-comprehensions==3.3.0 flake8-executable==2.0.4 +flake8-logging-format==0.9.0 git+https://github.com/malfet/flake8-coding.git flake8-pyi==20.5.0 mccabe==0.6.1 diff --git a/torch/backends/_nnapi/serializer.py b/torch/backends/_nnapi/serializer.py index 18630308b31c..d16bfea22215 100644 --- a/torch/backends/_nnapi/serializer.py +++ b/torch/backends/_nnapi/serializer.py @@ -491,7 +491,7 @@ class _NnapiSerializer: raise Exception("Flexible size is not supported for this operand.") if s < 0: # runtime flex - LOG.warn(f"Operand {oper} has runtime flex shape") + LOG.warning(f"Operand {oper} has runtime flex shape") return op_id, oper def get_tensor_operand_or_constant(self, jitval, dim_order=DimOrder.PRESUMED_CONTIGUOUS): diff --git a/torch/package/_importlib.py b/torch/package/_importlib.py index 63c9d7024bfb..62cabd7293a4 100644 --- a/torch/package/_importlib.py +++ b/torch/package/_importlib.py @@ -61,7 +61,7 @@ def _calc___package__(globals): spec = globals.get("__spec__") if package is not None: if spec is not None and package != spec.parent: - _warnings.warn( + _warnings.warn( # noqa: G010 "__package__ != __spec__.parent " f"({package!r} != {spec.parent!r})", ImportWarning, stacklevel=3, @@ -70,7 +70,7 @@ def _calc___package__(globals): elif spec is not None: return spec.parent else: - _warnings.warn( + _warnings.warn( # noqa: G010 "can't resolve package from __spec__ or __package__, " "falling back on __name__ and __path__", ImportWarning,