Skip to content

Commit 6f98c59

Browse files
authored
Enable Ruff PLR (Pylint Refactor) (#13307)
1 parent 3e83e42 commit 6f98c59

File tree

8 files changed

+18
-8
lines changed

8 files changed

+18
-8
lines changed

pyproject.toml

+7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ select = [
4646
"N", # pep8-naming
4747
"PGH", # pygrep-hooks
4848
"PLC", # Pylint Convention
49+
"PLR", # Pylint Refactor
4950
"RUF", # Ruff-specific and unused-noqa
5051
"TRY", # tryceratops
5152
"UP", # pyupgrade
@@ -142,6 +143,12 @@ ignore = [
142143
# Used for direct, non-subclass type comparison, for example: `type(val) is str`
143144
# see https://github.com/astral-sh/ruff/issues/6465
144145
"E721", # Do not compare types, use `isinstance()`
146+
# Leave the size and complexity of tests to human interpretation
147+
"PLR09", # Too many ...
148+
# Too many magic number "2" that are preferable inline. https://github.com/astral-sh/ruff/issues/10009
149+
"PLR2004", # Magic value used in comparison, consider replacing `{value}` with a constant variable
150+
# Keep codeflow path separation explicit
151+
"PLR5501", # Use `elif` instead of `else` then `if`, to reduce indentation
145152
# Mostly from scripts and tests, it's ok to have messages passed directly to exceptions
146153
"TRY003", # Avoid specifying long messages outside the exception class
147154
# Slower and more verbose https://github.com/astral-sh/ruff/issues/7871

scripts/create_baseline_stubs.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import subprocess
1919
import sys
2020
import urllib.parse
21+
from http import HTTPStatus
2122
from importlib.metadata import distribution
2223

2324
import aiohttp
@@ -72,7 +73,7 @@ def run_ruff(stub_dir: str) -> None:
7273
async def get_project_urls_from_pypi(project: str, session: aiohttp.ClientSession) -> dict[str, str]:
7374
pypi_root = f"https://pypi.org/pypi/{urllib.parse.quote(project)}"
7475
async with session.get(f"{pypi_root}/json") as response:
75-
if response.status != 200:
76+
if response.status != HTTPStatus.OK:
7677
return {}
7778
j: dict[str, dict[str, dict[str, str]]]
7879
j = await response.json()
@@ -107,7 +108,7 @@ async def get_upstream_repo_url(project: str) -> str | None:
107108
# truncate to https://site.com/user/repo
108109
upstream_repo_url = "/".join(url.split("/")[:5])
109110
async with session.get(upstream_repo_url) as response:
110-
if response.status == 200:
111+
if response.status == HTTPStatus.OK:
111112
return upstream_repo_url
112113
return None
113114

scripts/stubsabot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ async def get_github_repo_info(session: aiohttp.ClientSession, stub_info: StubMe
308308
assert len(Path(url_path).parts) == 2
309309
github_tags_info_url = f"https://api.github.com/repos/{url_path}/tags"
310310
async with session.get(github_tags_info_url, headers=get_github_api_headers()) as response:
311-
if response.status == 200:
311+
if response.status == HTTPStatus.OK:
312312
tags: list[dict[str, Any]] = await response.json()
313313
assert isinstance(tags, list)
314314
return GitHubInfo(repo_path=url_path, tags=tags)

stdlib/asyncio/__init__.pyi

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
# ruff: noqa: PLR5501 # This condition is so big, it's clearer to keep to platform condition in two blocks
2+
# Can't NOQA on a specific line: https://github.com/plinss/flake8-noqa/issues/22
13
import sys
24
from collections.abc import Awaitable, Coroutine, Generator
35
from typing import Any, TypeVar

stdlib/importlib/readers.pyi

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ if sys.version_info >= (3, 10):
1616
from zipimport import zipimporter
1717

1818
if sys.version_info >= (3, 11):
19-
import importlib.resources.abc as abc
19+
from importlib.resources import abc
2020
else:
21-
import importlib.abc as abc
21+
from importlib import abc
2222

2323
if sys.version_info >= (3, 10):
2424
if sys.version_info >= (3, 11):

stubs/gevent/gevent/libev/corecext.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ from types import TracebackType
55
from typing import Any
66
from typing_extensions import ParamSpec
77

8-
import gevent.libev.watcher as watcher
98
from gevent._ffi.loop import _ErrorHandler
109
from gevent._types import _Callback
10+
from gevent.libev import watcher
1111

1212
# this c extension is only available on posix
1313
if sys.platform != "win32":

stubs/gevent/gevent/libev/corecffi.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import sys
22
from _typeshed import FileDescriptor
33
from collections.abc import Sequence
44

5-
import gevent.libev.watcher as watcher
65
from gevent._ffi.loop import AbstractLoop
6+
from gevent.libev import watcher
77

88
def get_version() -> str: ...
99
def get_header_version() -> str: ...

stubs/gevent/gevent/libuv/loop.pyi

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import sys
22
from _typeshed import FileDescriptor
33
from typing import NamedTuple
44

5-
import gevent.libuv.watcher as watcher
65
from gevent._ffi.loop import AbstractLoop
76
from gevent._types import _IoWatcher
7+
from gevent.libuv import watcher
88

99
def get_version() -> str: ...
1010
def get_header_version() -> str: ...

0 commit comments

Comments
 (0)