Skip to content

Commit 556ae16

Browse files
authored
Some improvements to linting (#18381)
1 parent 777b2a3 commit 556ae16

File tree

12 files changed

+26
-40
lines changed

12 files changed

+26
-40
lines changed

misc/upload-pypi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828

2929
def is_whl_or_tar(name: str) -> bool:
30-
return name.endswith(".tar.gz") or name.endswith(".whl")
30+
return name.endswith((".tar.gz", ".whl"))
3131

3232

3333
def item_ok_for_pypi(name: str) -> bool:

mypy/build.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,8 @@
2525
import sys
2626
import time
2727
import types
28-
from collections.abc import Iterator, Mapping, Sequence
29-
from typing import (
30-
TYPE_CHECKING,
31-
AbstractSet,
32-
Any,
33-
Callable,
34-
ClassVar,
35-
Final,
36-
NamedTuple,
37-
NoReturn,
38-
TextIO,
39-
)
28+
from collections.abc import Iterator, Mapping, Sequence, Set as AbstractSet
29+
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Final, NamedTuple, NoReturn, TextIO
4030
from typing_extensions import TypeAlias as _TypeAlias, TypedDict
4131

4232
import mypy.semanal_main

mypy/checker.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,9 @@
44

55
import itertools
66
from collections import defaultdict
7-
from collections.abc import Iterable, Iterator, Mapping, Sequence
7+
from collections.abc import Iterable, Iterator, Mapping, Sequence, Set as AbstractSet
88
from contextlib import ExitStack, contextmanager
9-
from typing import (
10-
AbstractSet,
11-
Callable,
12-
Final,
13-
Generic,
14-
NamedTuple,
15-
Optional,
16-
TypeVar,
17-
Union,
18-
cast,
19-
overload,
20-
)
9+
from typing import Callable, Final, Generic, NamedTuple, Optional, TypeVar, Union, cast, overload
2110
from typing_extensions import TypeAlias as _TypeAlias
2211

2312
import mypy.checkexpr

mypy/dmypy_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import sys
1717
import time
1818
import traceback
19-
from collections.abc import Sequence
19+
from collections.abc import Sequence, Set as AbstractSet
2020
from contextlib import redirect_stderr, redirect_stdout
21-
from typing import AbstractSet, Any, Callable, Final
21+
from typing import Any, Callable, Final
2222
from typing_extensions import TypeAlias as _TypeAlias
2323

2424
import mypy.build

mypy/fswatcher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
from __future__ import annotations
44

55
import os
6-
from collections.abc import Iterable
7-
from typing import AbstractSet, NamedTuple
6+
from collections.abc import Iterable, Set as AbstractSet
7+
from typing import NamedTuple
88

99
from mypy.fscache import FileSystemCache
1010

mypy/graph_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from __future__ import annotations
44

5-
from collections.abc import Iterable, Iterator
6-
from typing import AbstractSet, TypeVar
5+
from collections.abc import Iterable, Iterator, Set as AbstractSet
6+
from typing import TypeVar
77

88
T = TypeVar("T")
99

mypy/semanal_shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ def require_bool_literal_argument(
453453
api: SemanticAnalyzerInterface | SemanticAnalyzerPluginInterface,
454454
expression: Expression,
455455
name: str,
456-
default: Literal[True] | Literal[False],
456+
default: Literal[True, False],
457457
) -> bool: ...
458458

459459

mypy/stubgenc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ def _from_sigs(cls, sigs: list[FunctionSig], is_abstract: bool = False) -> CFunc
203203
sigs[0].name, "\n".join(sig.format_sig()[:-4] for sig in sigs), is_abstract
204204
)
205205

206-
def __get__(self) -> None:
206+
def __get__(self) -> None: # noqa: PLE0302
207207
"""
208208
This exists to make this object look like a method descriptor and thus
209209
return true for CStubGenerator.ismethod()

mypy/stubtest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
import typing_extensions
2626
import warnings
2727
from collections import defaultdict
28-
from collections.abc import Iterator
28+
from collections.abc import Iterator, Set as AbstractSet
2929
from contextlib import redirect_stderr, redirect_stdout
3030
from functools import singledispatch
3131
from pathlib import Path
32-
from typing import AbstractSet, Any, Generic, TypeVar, Union
32+
from typing import Any, Generic, TypeVar, Union
3333
from typing_extensions import get_origin, is_typeddict
3434

3535
import mypy.build

mypy/test/testgraph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
import sys
6-
from typing import AbstractSet
6+
from collections.abc import Set as AbstractSet
77

88
from mypy.build import BuildManager, BuildSourceSet, State, order_ascc, sorted_components
99
from mypy.errors import Errors

mypyc/codegen/emit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ def emit_box(
10341034
self.emit_line(f"if (unlikely({dest} == NULL))")
10351035
self.emit_line(" CPyError_OutOfMemory();")
10361036
# TODO: Fail if dest is None
1037-
for i in range(0, len(typ.types)):
1037+
for i in range(len(typ.types)):
10381038
if not typ.is_unboxed:
10391039
self.emit_line(f"PyTuple_SET_ITEM({dest}, {i}, {src}.f{i}")
10401040
else:

pyproject.toml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ force-exclude = '''
102102

103103
[tool.ruff]
104104
line-length = 99
105-
target-version = "py38"
105+
target-version = "py39"
106106
fix = true
107107

108108
extend-exclude = [
@@ -126,11 +126,13 @@ select = [
126126
"B", # flake8-bugbear
127127
"I", # isort
128128
"N", # pep8-naming
129+
"PIE", # flake8-pie
130+
"PLE", # pylint error
129131
"RUF100", # Unused noqa comments
130132
"PGH004", # blanket noqa comments
131133
"UP", # pyupgrade
132134
"C4", # flake8-comprehensions
133-
"SIM201", "SIM202", # simplify comparisons involving not
135+
"SIM201", "SIM202", "SIM222", "SIM223", # flake8-simplify
134136
"ISC001", # implicitly concatenated string
135137
"RET501", "RET502", # better return None handling
136138
]
@@ -149,7 +151,10 @@ ignore = [
149151
"N806", # UPPER_CASE used for constant local variables
150152
"UP031", # Use format specifiers instead of percent format
151153
"UP032", # 'f-string always preferable to format' is controversial
154+
"C409", # https://github.com/astral-sh/ruff/issues/12912
155+
"C420", # reads a little worse. fromkeys predates dict comprehensions
152156
"C416", # There are a few cases where it's nice to have names for the dict items
157+
"PIE790", # there's nothing wrong with pass
153158
]
154159

155160
unfixable = [
@@ -158,6 +163,8 @@ unfixable = [
158163
"F602", # automatic fix might obscure issue
159164
"B018", # automatic fix might obscure issue
160165
"UP036", # sometimes it's better to just noqa this
166+
"SIM222", # automatic fix might obscure issue
167+
"SIM223", # automatic fix might obscure issue
161168
]
162169

163170
[tool.ruff.lint.per-file-ignores]

0 commit comments

Comments
 (0)