From 2c6573ab7624bb35478e5b7e8276790eb7c5c630 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 28 Dec 2024 20:39:05 -0500 Subject: [PATCH 1/4] Enable Ruff TC (flake8-type-checking) --- pyproject.toml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 424fb108d175..522278cb1893 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,6 +42,7 @@ select = [ "I", # isort "PGH", # pygrep-hooks "RUF", # Ruff-specific and unused-noqa + "TC", # flake8-quotes "UP", # pyupgrade "YTT", # flake8-2020 # Flake8 base rules @@ -88,11 +89,15 @@ ignore = [ ### # Rules we don't want or don't agree with ### - # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 - "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` + # We'll end up importing nearly everything anyway and have good runtime test coverage. Keep it simple. + "TC001", # Move application import `{}` into a type-checking block + "TC002", # Move third-party import `{}` into a type-checking block + "TC003", # Move standard library import `{}` into a type-checking block # Used for direct, non-subclass type comparison, for example: `type(val) is str` # see https://github.com/astral-sh/ruff/issues/6465 "E721", # Do not compare types, use `isinstance()` + # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 + "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` ### # False-positives, but already checked by type-checkers ### From da8808fc8024205f572580821107e073f4662f47 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 28 Dec 2024 20:46:48 -0500 Subject: [PATCH 2/4] typo --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 522278cb1893..493e82f44fe2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ select = [ "I", # isort "PGH", # pygrep-hooks "RUF", # Ruff-specific and unused-noqa - "TC", # flake8-quotes + "TC", # flake8-type-checking "UP", # pyupgrade "YTT", # flake8-2020 # Flake8 base rules From b1b20e909460bc8041f0cea97272fba536bf01eb Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 13:46:34 -0500 Subject: [PATCH 3/4] Select rules explicitly --- pyproject.toml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d0fe8642cc6b..65a98347b0d3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,7 +45,6 @@ select = [ "N", # pep8-naming "PGH", # pygrep-hooks "RUF", # Ruff-specific and unused-noqa - "TC", # flake8-type-checking "UP", # pyupgrade "YTT", # flake8-2020 # Flake8 base rules @@ -54,6 +53,11 @@ select = [ "W", # pycodestyle Warning # Only include flake8-annotations rules that are autofixable. Otherwise leave this to mypy+pyright "ANN2", + # Don't include TC rules that create a TYPE_CHECKING block or stringifies annotations + "TC004", # Move import `{qualified_name}` out of type-checking block. Import is used for more than type hinting. + "TC005", # Found empty type-checking block + # "TC008", # TODO: Enable when out of preview + "TC010", # Invalid string member in `X | Y`-style union type # Most refurb rules are in preview and can be opinionated, # consider them individually as they come out of preview (last check: 0.8.4) "FURB105", # Unnecessary empty string passed to `print` @@ -104,10 +108,6 @@ ignore = [ ### # Rules we don't want or don't agree with ### - # We'll end up importing nearly everything anyway and have good runtime test coverage. Keep it simple. - "TC001", # Move application import `{}` into a type-checking block - "TC002", # Move third-party import `{}` into a type-checking block - "TC003", # Move standard library import `{}` into a type-checking block # Used for direct, non-subclass type comparison, for example: `type(val) is str` # see https://github.com/astral-sh/ruff/issues/6465 "E721", # Do not compare types, use `isinstance()` From b59aa2a885c8483bd9e1941d17b025f7967aadad Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 13:50:09 -0500 Subject: [PATCH 4/4] don't reorder if not touching the section --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 65a98347b0d3..0c9abdfea3a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,11 +108,11 @@ ignore = [ ### # Rules we don't want or don't agree with ### + # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 + "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` # Used for direct, non-subclass type comparison, for example: `type(val) is str` # see https://github.com/astral-sh/ruff/issues/6465 "E721", # Do not compare types, use `isinstance()` - # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 - "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` ### # False-positives, but already checked by type-checkers ###