From eee5ab14278e72e79a4f8a8e508700ff9016d963 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 26 Dec 2024 16:11:25 -0500 Subject: [PATCH 1/9] Enable Ruff SIM --- pyproject.toml | 7 +++++-- scripts/stubsabot.py | 15 ++++----------- stdlib/_ssl.pyi | 4 +--- tests/pytype_test.py | 5 +---- tests/stubtest_third_party.py | 15 +++++---------- 5 files changed, 16 insertions(+), 30 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 501066318b0b..7f3afb7a332a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,6 +41,7 @@ select = [ "FA", # flake8-future-annotations "I", # isort "RUF", # Ruff-specific and unused-noqa + "SIM", # flake8-simplify "UP", # pyupgrade # Flake8 base rules "E", # pycodestyle Error @@ -86,11 +87,13 @@ 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()` + # contextlib.suppress is roughly 3x slower than try/except + "SIM105", # flake8-simplify: use-contextlib-suppress + # 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 ### diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index aee09eb3e8a2..5e4389504245 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -200,10 +200,7 @@ def all_py_files_in_source_are_in_py_typed_dirs(source: zipfile.ZipFile | tarfil if not all_python_files: return False - for path in all_python_files: - if not any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs): - return False - return True + return all(any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs) for path in all_python_files) async def release_contains_py_typed(release_to_download: PypiReleaseDownload, *, session: aiohttp.ClientSession) -> bool: @@ -747,10 +744,7 @@ async def main() -> None: parser.add_argument("distributions", nargs="*", help="Distributions to update, default = all") args = parser.parse_args() - if args.distributions: - dists_to_update = args.distributions - else: - dists_to_update = [path.name for path in STUBS_PATH.iterdir()] + dists_to_update = args.distributions if args.distributions else [path.name for path in STUBS_PATH.iterdir()] if args.action_level > ActionLevel.nothing: subprocess.run(["git", "update-index", "--refresh"], capture_output=True) @@ -765,9 +759,8 @@ async def main() -> None: print(f"Cannot run stubsabot, as uncommitted changes are present in {changed_files}!") sys.exit(1) - if args.action_level > ActionLevel.fork: - if os.environ.get("GITHUB_TOKEN") is None: - raise ValueError("GITHUB_TOKEN environment variable must be set") + if args.action_level > ActionLevel.fork and os.environ.get("GITHUB_TOKEN") is None: + raise ValueError("GITHUB_TOKEN environment variable must be set") denylist = {"gdb"} # gdb is not a pypi distribution diff --git a/stdlib/_ssl.pyi b/stdlib/_ssl.pyi index 1a068b997539..d8a2e91ddf1f 100644 --- a/stdlib/_ssl.pyi +++ b/stdlib/_ssl.pyi @@ -240,9 +240,7 @@ OP_SINGLE_ECDH_USE: int OP_NO_COMPRESSION: int OP_ENABLE_MIDDLEBOX_COMPAT: int OP_NO_RENEGOTIATION: int -if sys.version_info >= (3, 11): - OP_IGNORE_UNEXPECTED_EOF: int -elif sys.version_info >= (3, 8) and sys.platform == "linux": +if sys.version_info >= (3, 11) or (sys.version_info >= (3, 8) and sys.platform == "linux"): OP_IGNORE_UNEXPECTED_EOF: int if sys.version_info >= (3, 12): OP_LEGACY_SERVER_CONNECT: int diff --git a/tests/pytype_test.py b/tests/pytype_test.py index 366d279f2844..02587d80b96e 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -228,10 +228,7 @@ def run_all_tests(*, files_to_test: Sequence[str], print_stderr: bool, dry_run: python_version = f"{sys.version_info.major}.{sys.version_info.minor}" print("Testing files with pytype...") for i, f in enumerate(files_to_test): - if dry_run: - stderr = None - else: - stderr = run_pytype(filename=f, python_version=python_version, missing_modules=missing_modules) + stderr = None if dry_run else run_pytype(filename=f, python_version=python_version, missing_modules=missing_modules) if stderr: if print_stderr: print(f"\n{stderr}") diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index e10fbf96c8f8..7f19265ceb7d 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -125,13 +125,11 @@ def run_stubtest( stubtest_env = os.environ | {"MYPYPATH": mypypath, "MYPY_FORCE_COLOR": "1"} # Perform some black magic in order to run stubtest inside uWSGI - if dist_name == "uWSGI": - if not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): - return False + if dist_name == "uWSGI" and not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): + return False - if dist_name == "gdb": - if not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): - return False + if dist_name == "gdb" and not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): + return False try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) @@ -390,10 +388,7 @@ def main() -> NoReturn: parser.add_argument("dists", metavar="DISTRIBUTION", type=str, nargs=argparse.ZERO_OR_MORE) args = parser.parse_args() - if len(args.dists) == 0: - dists = sorted(STUBS_PATH.iterdir()) - else: - dists = [STUBS_PATH / d for d in args.dists] + dists = sorted(STUBS_PATH.iterdir()) if len(args.dists) == 0 else [STUBS_PATH / d for d in args.dists] result = 0 for i, dist in enumerate(dists): From a96249ec7ff310888331b8cb875c035fc6fc426f Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 26 Dec 2024 16:33:10 -0500 Subject: [PATCH 2/9] Work around PYI002+SIM114 incompatibility --- stdlib/_ssl.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_ssl.pyi b/stdlib/_ssl.pyi index d8a2e91ddf1f..e39ab5eb6de8 100644 --- a/stdlib/_ssl.pyi +++ b/stdlib/_ssl.pyi @@ -240,7 +240,7 @@ OP_SINGLE_ECDH_USE: int OP_NO_COMPRESSION: int OP_ENABLE_MIDDLEBOX_COMPAT: int OP_NO_RENEGOTIATION: int -if sys.version_info >= (3, 11) or (sys.version_info >= (3, 8) and sys.platform == "linux"): +if sys.version_info >= (3, 11) or sys.platform == "linux": OP_IGNORE_UNEXPECTED_EOF: int if sys.version_info >= (3, 12): OP_LEGACY_SERVER_CONNECT: int From 1daf81f84dfaa245cd416bd808cf45feee6ea758 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 26 Dec 2024 17:19:40 -0500 Subject: [PATCH 3/9] Disable SIM102 and SIM108 --- pyproject.toml | 5 ++++- scripts/stubsabot.py | 16 ++++++++++++---- tests/pytype_test.py | 5 ++++- tests/stubtest_third_party.py | 15 ++++++++++----- 4 files changed, 30 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7f3afb7a332a..894824676a30 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -90,8 +90,11 @@ ignore = [ # 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()` + # Long single-line ternaries tend to be less readable with our 130 line-length + "SIM102", # Use a single if statement instead of nested if statements + "SIM108", # Use ternary operator {contents} instead of if-else-block # contextlib.suppress is roughly 3x slower than try/except - "SIM105", # flake8-simplify: use-contextlib-suppress + "SIM105", # Use contextlib.suppress() instead of try-except-pass # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` ### diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index 5e4389504245..4af8799b764b 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -200,7 +200,11 @@ def all_py_files_in_source_are_in_py_typed_dirs(source: zipfile.ZipFile | tarfil if not all_python_files: return False - return all(any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs) for path in all_python_files) + return all( + # fmt: skip + any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs) + for path in all_python_files + ) async def release_contains_py_typed(release_to_download: PypiReleaseDownload, *, session: aiohttp.ClientSession) -> bool: @@ -744,7 +748,10 @@ async def main() -> None: parser.add_argument("distributions", nargs="*", help="Distributions to update, default = all") args = parser.parse_args() - dists_to_update = args.distributions if args.distributions else [path.name for path in STUBS_PATH.iterdir()] + if args.distributions: + dists_to_update = args.distributions + else: + dists_to_update = [path.name for path in STUBS_PATH.iterdir()] if args.action_level > ActionLevel.nothing: subprocess.run(["git", "update-index", "--refresh"], capture_output=True) @@ -759,8 +766,9 @@ async def main() -> None: print(f"Cannot run stubsabot, as uncommitted changes are present in {changed_files}!") sys.exit(1) - if args.action_level > ActionLevel.fork and os.environ.get("GITHUB_TOKEN") is None: - raise ValueError("GITHUB_TOKEN environment variable must be set") + if args.action_level > ActionLevel.fork: + if os.environ.get("GITHUB_TOKEN") is None: + raise ValueError("GITHUB_TOKEN environment variable must be set") denylist = {"gdb"} # gdb is not a pypi distribution diff --git a/tests/pytype_test.py b/tests/pytype_test.py index 02587d80b96e..366d279f2844 100755 --- a/tests/pytype_test.py +++ b/tests/pytype_test.py @@ -228,7 +228,10 @@ def run_all_tests(*, files_to_test: Sequence[str], print_stderr: bool, dry_run: python_version = f"{sys.version_info.major}.{sys.version_info.minor}" print("Testing files with pytype...") for i, f in enumerate(files_to_test): - stderr = None if dry_run else run_pytype(filename=f, python_version=python_version, missing_modules=missing_modules) + if dry_run: + stderr = None + else: + stderr = run_pytype(filename=f, python_version=python_version, missing_modules=missing_modules) if stderr: if print_stderr: print(f"\n{stderr}") diff --git a/tests/stubtest_third_party.py b/tests/stubtest_third_party.py index 7f19265ceb7d..e10fbf96c8f8 100755 --- a/tests/stubtest_third_party.py +++ b/tests/stubtest_third_party.py @@ -125,11 +125,13 @@ def run_stubtest( stubtest_env = os.environ | {"MYPYPATH": mypypath, "MYPY_FORCE_COLOR": "1"} # Perform some black magic in order to run stubtest inside uWSGI - if dist_name == "uWSGI" and not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): - return False + if dist_name == "uWSGI": + if not setup_uwsgi_stubtest_command(dist, venv_dir, stubtest_cmd): + return False - if dist_name == "gdb" and not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): - return False + if dist_name == "gdb": + if not setup_gdb_stubtest_command(venv_dir, stubtest_cmd): + return False try: subprocess.run(stubtest_cmd, env=stubtest_env, check=True, capture_output=True) @@ -388,7 +390,10 @@ def main() -> NoReturn: parser.add_argument("dists", metavar="DISTRIBUTION", type=str, nargs=argparse.ZERO_OR_MORE) args = parser.parse_args() - dists = sorted(STUBS_PATH.iterdir()) if len(args.dists) == 0 else [STUBS_PATH / d for d in args.dists] + if len(args.dists) == 0: + dists = sorted(STUBS_PATH.iterdir()) + else: + dists = [STUBS_PATH / d for d in args.dists] result = 0 for i, dist in enumerate(dists): From 7d5868ef24ea6f59a72ba5fa53b8adbde10958f1 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sat, 28 Dec 2024 21:23:18 -0500 Subject: [PATCH 4/9] Disable SIM110 --- pyproject.toml | 2 ++ scripts/stubsabot.py | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index b55d68ced943..bc6dc341a04e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -95,6 +95,8 @@ ignore = [ # Long single-line ternaries tend to be less readable with our 130 line-length "SIM102", # Use a single if statement instead of nested if statements "SIM108", # Use ternary operator {contents} instead of if-else-block + # Explicit short-circuiting loops can be more readable and any/all on a single line + "SIM110", # contextlib.suppress is roughly 3x slower than try/except "SIM105", # Use contextlib.suppress() instead of try-except-pass # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 diff --git a/scripts/stubsabot.py b/scripts/stubsabot.py index 4af8799b764b..aee09eb3e8a2 100644 --- a/scripts/stubsabot.py +++ b/scripts/stubsabot.py @@ -200,11 +200,10 @@ def all_py_files_in_source_are_in_py_typed_dirs(source: zipfile.ZipFile | tarfil if not all_python_files: return False - return all( - # fmt: skip - any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs) - for path in all_python_files - ) + for path in all_python_files: + if not any(py_typed_dir in path.parents for py_typed_dir in py_typed_dirs): + return False + return True async def release_contains_py_typed(release_to_download: PypiReleaseDownload, *, session: aiohttp.ClientSession) -> bool: From 93d24f8162b9fa7541fadddf4feb54ab4d5f850b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 29 Dec 2024 02:25:04 +0000 Subject: [PATCH 5/9] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/asyncio/__init__.pyi | 182 +----------------------------------- 1 file changed, 2 insertions(+), 180 deletions(-) diff --git a/stdlib/asyncio/__init__.pyi b/stdlib/asyncio/__init__.pyi index 7c3ac6ede4fe..02c0d63a323b 100644 --- a/stdlib/asyncio/__init__.pyi +++ b/stdlib/asyncio/__init__.pyi @@ -410,94 +410,7 @@ if sys.platform == "win32": "WindowsSelectorEventLoopPolicy", # from windows_events "WindowsProactorEventLoopPolicy", # from windows_events ) - elif sys.version_info >= (3, 10): - __all__ = ( - "BaseEventLoop", # from base_events - "Server", # from base_events - "coroutine", # from coroutines - "iscoroutinefunction", # from coroutines - "iscoroutine", # from coroutines - "AbstractEventLoopPolicy", # from events - "AbstractEventLoop", # from events - "AbstractServer", # from events - "Handle", # from events - "TimerHandle", # from events - "get_event_loop_policy", # from events - "set_event_loop_policy", # from events - "get_event_loop", # from events - "set_event_loop", # from events - "new_event_loop", # from events - "get_child_watcher", # from events - "set_child_watcher", # from events - "_set_running_loop", # from events - "get_running_loop", # from events - "_get_running_loop", # from events - "CancelledError", # from exceptions - "InvalidStateError", # from exceptions - "TimeoutError", # from exceptions - "IncompleteReadError", # from exceptions - "LimitOverrunError", # from exceptions - "SendfileNotAvailableError", # from exceptions - "Future", # from futures - "wrap_future", # from futures - "isfuture", # from futures - "Lock", # from locks - "Event", # from locks - "Condition", # from locks - "Semaphore", # from locks - "BoundedSemaphore", # from locks - "BaseProtocol", # from protocols - "Protocol", # from protocols - "DatagramProtocol", # from protocols - "SubprocessProtocol", # from protocols - "BufferedProtocol", # from protocols - "run", # from runners - "Queue", # from queues - "PriorityQueue", # from queues - "LifoQueue", # from queues - "QueueFull", # from queues - "QueueEmpty", # from queues - "StreamReader", # from streams - "StreamWriter", # from streams - "StreamReaderProtocol", # from streams - "open_connection", # from streams - "start_server", # from streams - "create_subprocess_exec", # from subprocess - "create_subprocess_shell", # from subprocess - "Task", # from tasks - "create_task", # from tasks - "FIRST_COMPLETED", # from tasks - "FIRST_EXCEPTION", # from tasks - "ALL_COMPLETED", # from tasks - "wait", # from tasks - "wait_for", # from tasks - "as_completed", # from tasks - "sleep", # from tasks - "gather", # from tasks - "shield", # from tasks - "ensure_future", # from tasks - "run_coroutine_threadsafe", # from tasks - "current_task", # from tasks - "all_tasks", # from tasks - "_register_task", # from tasks - "_unregister_task", # from tasks - "_enter_task", # from tasks - "_leave_task", # from tasks - "to_thread", # from threads - "BaseTransport", # from transports - "ReadTransport", # from transports - "WriteTransport", # from transports - "Transport", # from transports - "DatagramTransport", # from transports - "SubprocessTransport", # from transports - "SelectorEventLoop", # from windows_events - "ProactorEventLoop", # from windows_events - "IocpProactor", # from windows_events - "DefaultEventLoopPolicy", # from windows_events - "WindowsSelectorEventLoopPolicy", # from windows_events - "WindowsProactorEventLoopPolicy", # from windows_events - ) - elif sys.version_info >= (3, 9): + elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9): __all__ = ( "BaseEventLoop", # from base_events "Server", # from base_events @@ -1059,98 +972,7 @@ else: "ThreadedChildWatcher", # from unix_events "DefaultEventLoopPolicy", # from unix_events ) - elif sys.version_info >= (3, 10): - __all__ = ( - "BaseEventLoop", # from base_events - "Server", # from base_events - "coroutine", # from coroutines - "iscoroutinefunction", # from coroutines - "iscoroutine", # from coroutines - "AbstractEventLoopPolicy", # from events - "AbstractEventLoop", # from events - "AbstractServer", # from events - "Handle", # from events - "TimerHandle", # from events - "get_event_loop_policy", # from events - "set_event_loop_policy", # from events - "get_event_loop", # from events - "set_event_loop", # from events - "new_event_loop", # from events - "get_child_watcher", # from events - "set_child_watcher", # from events - "_set_running_loop", # from events - "get_running_loop", # from events - "_get_running_loop", # from events - "CancelledError", # from exceptions - "InvalidStateError", # from exceptions - "TimeoutError", # from exceptions - "IncompleteReadError", # from exceptions - "LimitOverrunError", # from exceptions - "SendfileNotAvailableError", # from exceptions - "Future", # from futures - "wrap_future", # from futures - "isfuture", # from futures - "Lock", # from locks - "Event", # from locks - "Condition", # from locks - "Semaphore", # from locks - "BoundedSemaphore", # from locks - "BaseProtocol", # from protocols - "Protocol", # from protocols - "DatagramProtocol", # from protocols - "SubprocessProtocol", # from protocols - "BufferedProtocol", # from protocols - "run", # from runners - "Queue", # from queues - "PriorityQueue", # from queues - "LifoQueue", # from queues - "QueueFull", # from queues - "QueueEmpty", # from queues - "StreamReader", # from streams - "StreamWriter", # from streams - "StreamReaderProtocol", # from streams - "open_connection", # from streams - "start_server", # from streams - "open_unix_connection", # from streams - "start_unix_server", # from streams - "create_subprocess_exec", # from subprocess - "create_subprocess_shell", # from subprocess - "Task", # from tasks - "create_task", # from tasks - "FIRST_COMPLETED", # from tasks - "FIRST_EXCEPTION", # from tasks - "ALL_COMPLETED", # from tasks - "wait", # from tasks - "wait_for", # from tasks - "as_completed", # from tasks - "sleep", # from tasks - "gather", # from tasks - "shield", # from tasks - "ensure_future", # from tasks - "run_coroutine_threadsafe", # from tasks - "current_task", # from tasks - "all_tasks", # from tasks - "_register_task", # from tasks - "_unregister_task", # from tasks - "_enter_task", # from tasks - "_leave_task", # from tasks - "to_thread", # from threads - "BaseTransport", # from transports - "ReadTransport", # from transports - "WriteTransport", # from transports - "Transport", # from transports - "DatagramTransport", # from transports - "SubprocessTransport", # from transports - "SelectorEventLoop", # from unix_events - "AbstractChildWatcher", # from unix_events - "SafeChildWatcher", # from unix_events - "FastChildWatcher", # from unix_events - "PidfdChildWatcher", # from unix_events - "MultiLoopChildWatcher", # from unix_events - "ThreadedChildWatcher", # from unix_events - "DefaultEventLoopPolicy", # from unix_events - ) - elif sys.version_info >= (3, 9): + elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9): __all__ = ( "BaseEventLoop", # from base_events "Server", # from base_events From 892301b062d8b11adfa7ce82889b4a91452110e0 Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 2 Jan 2025 18:43:14 -0500 Subject: [PATCH 6/9] Apply suggestions from code review --- stdlib/asyncio/__init__.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/asyncio/__init__.pyi b/stdlib/asyncio/__init__.pyi index 02c0d63a323b..89a8143c5f7f 100644 --- a/stdlib/asyncio/__init__.pyi +++ b/stdlib/asyncio/__init__.pyi @@ -410,7 +410,7 @@ if sys.platform == "win32": "WindowsSelectorEventLoopPolicy", # from windows_events "WindowsProactorEventLoopPolicy", # from windows_events ) - elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9): + elif sys.version_info >= (3, 9): __all__ = ( "BaseEventLoop", # from base_events "Server", # from base_events @@ -972,7 +972,7 @@ else: "ThreadedChildWatcher", # from unix_events "DefaultEventLoopPolicy", # from unix_events ) - elif sys.version_info >= (3, 10) or sys.version_info >= (3, 9): + elif sys.version_info >= (3, 9): __all__ = ( "BaseEventLoop", # from base_events "Server", # from base_events From 818c0d3d4a5bdc259a1a8630c97ace962cd9425f Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 5 Jan 2025 22:03:48 -0500 Subject: [PATCH 7/9] More specific SIM selection --- pyproject.toml | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3088735922e5..c7ee046cb289 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ select = [ "N", # pep8-naming "PGH", # pygrep-hooks "RUF", # Ruff-specific and unused-noqa - "SIM", # flake8-simplify "UP", # pyupgrade "YTT", # flake8-2020 # Flake8 base rules @@ -55,11 +54,6 @@ 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` @@ -94,6 +88,26 @@ select = [ # "PYI061", # TODO: Enable when out of preview "PYI062", # Duplicate literal member `{}` "PYI064", # `Final[Literal[{literal}]]` can be replaced with a bare Final + # flake8-simplify, excluding rules that can reduce performance or readability due to long line formatting + "SIM101", # Multiple `isinstance` calls for `{name}`, merge into a single call + "SIM103", # Return the condition `{condition}` directly + "SIM107", # Don't use return in `try-except` and `finally` + "SIM109", # Use `{replacement}` instead of multiple equality comparisons + "SIM112", # Use capitalized environment variable `{expected}` instead of `{actual}` + "SIM113", # Use `enumerate()` for index variable `{index}` in `for` loop + "SIM114", # Combine `if` branches using logical `or` operator + "SIM115", # Use a context manager for opening files + "SIM118", # Use key `{operator}` dict instead of key `{operator} dict.keys()` + "SIM2", # flake8-simplify conditional ordering rules + "SIM300", # Yoda condition detected + "SIM401", # Use `{contents}` instead of an if block + "SIM910", # Use {expected}` instead of `{actual}` (dict-get-with-none-default) + "SIM911", # Use {expected}` instead of `{actual}` (zip-dict-keys-and-values) + # 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 ] extend-safe-fixes = [ "UP036", # Remove unnecessary `sys.version_info` blocks @@ -117,13 +131,6 @@ ignore = [ # 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()` - # Long single-line ternaries tend to be less readable with our 130 line-length - "SIM102", # Use a single if statement instead of nested if statements - "SIM108", # Use ternary operator {contents} instead of if-else-block - # Explicit short-circuiting loops can be more readable and any/all on a single line - "SIM110", - # contextlib.suppress is roughly 3x slower than try/except - "SIM105", # Use contextlib.suppress() instead of try-except-pass # Slower and more verbose https://github.com/astral-sh/ruff/issues/7871 "UP038", # Use `X | Y` in `isinstance` call instead of `(X, Y)` ### From b40aa9bbfb82ba55068d217dd3554209befbed2d Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 5 Jan 2025 22:08:26 -0500 Subject: [PATCH 8/9] Expand SIM2 --- pyproject.toml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 14f1cb079b65..2525c1236221 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -99,7 +99,16 @@ select = [ "SIM114", # Combine `if` branches using logical `or` operator "SIM115", # Use a context manager for opening files "SIM118", # Use key `{operator}` dict instead of key `{operator} dict.keys()` - "SIM2", # flake8-simplify conditional ordering rules + "SIM201", # Use `{left} != {right}` instead of not `{left} == {right}` + "SIM202", # Use `{left} == {right}` instead of not `{left} != {right}` + "SIM208", # Use `{expr}` instead of `not (not {expr})` + "SIM210", # Remove unnecessary `True if ... else False` + "SIM211", # Use `not ...` instead of `False if ... else True` + "SIM212", # Use `{expr_else} if {expr_else} else {expr_body}` instead of `{expr_body} if not {expr_else} else {expr_else}` + "SIM220", # Use `False` instead of `{name} and not {name}` + "SIM221", # Use `True` instead of `{name} or not {name}` + "SIM222", # Use `{expr}` instead of `{replaced}` + "SIM223", # Use `{expr}` instead of `{replaced}` "SIM300", # Yoda condition detected "SIM401", # Use `{contents}` instead of an if block "SIM910", # Use {expected}` instead of `{actual}` (dict-get-with-none-default) From c52fedaffbf04efbe6382cf580b172923a21b971 Mon Sep 17 00:00:00 2001 From: Avasam Date: Sun, 5 Jan 2025 22:35:55 -0500 Subject: [PATCH 9/9] typo --- pyproject.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 2525c1236221..e4506f5d9d0c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,8 +111,8 @@ select = [ "SIM223", # Use `{expr}` instead of `{replaced}` "SIM300", # Yoda condition detected "SIM401", # Use `{contents}` instead of an if block - "SIM910", # Use {expected}` instead of `{actual}` (dict-get-with-none-default) - "SIM911", # Use {expected}` instead of `{actual}` (zip-dict-keys-and-values) + "SIM910", # Use `{expected}` instead of `{actual}` (dict-get-with-none-default) + "SIM911", # Use `{expected}` instead of `{actual}` (zip-dict-keys-and-values) # 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