From 33938cfddd03ef3452ebbf30b70f6b72355a337d Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Sat, 24 Feb 2024 07:13:53 +0000 Subject: [PATCH] [BE][Ez] Update ruff to 0.2.2 (#120517) Updates ruff to 0.2.2. This updates the config and handles some of the new rules that have come out of preview. Pull Request resolved: https://github.com/pytorch/pytorch/pull/120517 Approved by: https://github.com/albanD --- .lintrunner.toml | 2 +- functorch/docs/source/conf.py | 3 --- pyproject.toml | 16 +++++++++++----- torchgen/gen.py | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.lintrunner.toml b/.lintrunner.toml index 024c1103fa6..d3910756f4c 100644 --- a/.lintrunner.toml +++ b/.lintrunner.toml @@ -2654,7 +2654,7 @@ init_command = [ 'python3', 'tools/linter/adapters/pip_init.py', '--dry-run={{DRYRUN}}', - 'ruff==0.1.14', + 'ruff==0.2.2', ] is_formatter = true diff --git a/functorch/docs/source/conf.py b/functorch/docs/source/conf.py index 68f02c8b810..8a1bf182dda 100644 --- a/functorch/docs/source/conf.py +++ b/functorch/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # # This file is execfile()d with the current directory set to its # containing dir. @@ -22,11 +21,9 @@ import functorch # source code directory, relative to this file, for sphinx-autobuild # sys.path.insert(0, os.path.abspath('../..')) -import torch RELEASE = os.environ.get("RELEASE", False) -import sys import pytorch_sphinx_theme diff --git a/pyproject.toml b/pyproject.toml index 9508ad05f07..b1fa4f9c930 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,7 +22,9 @@ target-version = ["py38", "py39", "py310", "py311"] [tool.ruff] target-version = "py38" +line-length = 120 +[tool.ruff.lint] # NOTE: Synchoronize the ignores with .flake8 ignore = [ # these ignores are from flake8-bugbear; please fix! @@ -31,7 +33,7 @@ ignore = [ "B019", "B023", "B028", # No explicit `stacklevel` keyword argument found - "B904", + "B904", # Migrate from TRY200 "E402", "C408", # C408 ignored because we like the dict keyword argument syntax "E501", # E501 is not flexible enough, we're using B950 instead @@ -56,6 +58,7 @@ ignore = [ "PYI041", "PYI056", "SIM102", "SIM103", "SIM112", # flake8-simplify code styles + "SIM113", # please fix "SIM105", # these ignores are from flake8-simplify. please fix or ignore with commented reason "SIM108", "SIM110", @@ -67,7 +70,6 @@ ignore = [ "UP006", # keep-runtime-typing "UP007", # keep-runtime-typing ] -line-length = 120 select = [ "B", "C4", @@ -109,15 +111,18 @@ select = [ "RUF015", # access first ele in constant time "RUF016", # type error non-integer index "RUF017", - "TRY200", + "TRY200", # TODO: migrate from deprecated alias "TRY302", "UP", ] -[tool.ruff.per-file-ignores] +[tool.ruff.lint.per-file-ignores] "__init__.py" = [ "F401", ] +"functorch/notebooks/**" = [ + "F401", +] "test/typing/reveal/**" = [ "F821", ] @@ -136,7 +141,8 @@ select = [ "RUF015", "UP", # We don't want to modify the jit test as they test specify syntax ] - +# autogenerated #TODO figure out why file level noqa is ignored +"torch/_inductor/fx_passes/serialized_patterns/**" = ["F401", "F501"] "torch/onnx/**" = [ "UP037", # ONNX does runtime type checking ] diff --git a/torchgen/gen.py b/torchgen/gen.py index 462d3b6d5dd..7407154b708 100644 --- a/torchgen/gen.py +++ b/torchgen/gen.py @@ -2428,9 +2428,9 @@ def gen_source_files( }, ) - cpu_fm.write("Functions.cpp", lambda: {}) + cpu_fm.write("Functions.cpp", dict) - core_fm.write("TensorMethods.cpp", lambda: {}) + core_fm.write("TensorMethods.cpp", dict) core_fm.write( "ATenOpList.cpp",