Skip to content

Commit

Permalink
Some improvements to linting (#18381)
Browse files Browse the repository at this point in the history
  • Loading branch information
hauntsaninja authored Dec 30, 2024
1 parent 777b2a3 commit 556ae16
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion misc/upload-pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@


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


def item_ok_for_pypi(name: str) -> bool:
Expand Down
14 changes: 2 additions & 12 deletions mypy/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,8 @@
import sys
import time
import types
from collections.abc import Iterator, Mapping, Sequence
from typing import (
TYPE_CHECKING,
AbstractSet,
Any,
Callable,
ClassVar,
Final,
NamedTuple,
NoReturn,
TextIO,
)
from collections.abc import Iterator, Mapping, Sequence, Set as AbstractSet
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Final, NamedTuple, NoReturn, TextIO
from typing_extensions import TypeAlias as _TypeAlias, TypedDict

import mypy.semanal_main
Expand Down
15 changes: 2 additions & 13 deletions mypy/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,9 @@

import itertools
from collections import defaultdict
from collections.abc import Iterable, Iterator, Mapping, Sequence
from collections.abc import Iterable, Iterator, Mapping, Sequence, Set as AbstractSet
from contextlib import ExitStack, contextmanager
from typing import (
AbstractSet,
Callable,
Final,
Generic,
NamedTuple,
Optional,
TypeVar,
Union,
cast,
overload,
)
from typing import Callable, Final, Generic, NamedTuple, Optional, TypeVar, Union, cast, overload
from typing_extensions import TypeAlias as _TypeAlias

import mypy.checkexpr
Expand Down
4 changes: 2 additions & 2 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import sys
import time
import traceback
from collections.abc import Sequence
from collections.abc import Sequence, Set as AbstractSet
from contextlib import redirect_stderr, redirect_stdout
from typing import AbstractSet, Any, Callable, Final
from typing import Any, Callable, Final
from typing_extensions import TypeAlias as _TypeAlias

import mypy.build
Expand Down
4 changes: 2 additions & 2 deletions mypy/fswatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from __future__ import annotations

import os
from collections.abc import Iterable
from typing import AbstractSet, NamedTuple
from collections.abc import Iterable, Set as AbstractSet
from typing import NamedTuple

from mypy.fscache import FileSystemCache

Expand Down
4 changes: 2 additions & 2 deletions mypy/graph_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from __future__ import annotations

from collections.abc import Iterable, Iterator
from typing import AbstractSet, TypeVar
from collections.abc import Iterable, Iterator, Set as AbstractSet
from typing import TypeVar

T = TypeVar("T")

Expand Down
2 changes: 1 addition & 1 deletion mypy/semanal_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def require_bool_literal_argument(
api: SemanticAnalyzerInterface | SemanticAnalyzerPluginInterface,
expression: Expression,
name: str,
default: Literal[True] | Literal[False],
default: Literal[True, False],
) -> bool: ...


Expand Down
2 changes: 1 addition & 1 deletion mypy/stubgenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def _from_sigs(cls, sigs: list[FunctionSig], is_abstract: bool = False) -> CFunc
sigs[0].name, "\n".join(sig.format_sig()[:-4] for sig in sigs), is_abstract
)

def __get__(self) -> None:
def __get__(self) -> None: # noqa: PLE0302
"""
This exists to make this object look like a method descriptor and thus
return true for CStubGenerator.ismethod()
Expand Down
4 changes: 2 additions & 2 deletions mypy/stubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
import typing_extensions
import warnings
from collections import defaultdict
from collections.abc import Iterator
from collections.abc import Iterator, Set as AbstractSet
from contextlib import redirect_stderr, redirect_stdout
from functools import singledispatch
from pathlib import Path
from typing import AbstractSet, Any, Generic, TypeVar, Union
from typing import Any, Generic, TypeVar, Union
from typing_extensions import get_origin, is_typeddict

import mypy.build
Expand Down
2 changes: 1 addition & 1 deletion mypy/test/testgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

import sys
from typing import AbstractSet
from collections.abc import Set as AbstractSet

from mypy.build import BuildManager, BuildSourceSet, State, order_ascc, sorted_components
from mypy.errors import Errors
Expand Down
2 changes: 1 addition & 1 deletion mypyc/codegen/emit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ def emit_box(
self.emit_line(f"if (unlikely({dest} == NULL))")
self.emit_line(" CPyError_OutOfMemory();")
# TODO: Fail if dest is None
for i in range(0, len(typ.types)):
for i in range(len(typ.types)):
if not typ.is_unboxed:
self.emit_line(f"PyTuple_SET_ITEM({dest}, {i}, {src}.f{i}")
else:
Expand Down
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ force-exclude = '''

[tool.ruff]
line-length = 99
target-version = "py38"
target-version = "py39"
fix = true

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

unfixable = [
Expand All @@ -158,6 +163,8 @@ unfixable = [
"F602", # automatic fix might obscure issue
"B018", # automatic fix might obscure issue
"UP036", # sometimes it's better to just noqa this
"SIM222", # automatic fix might obscure issue
"SIM223", # automatic fix might obscure issue
]

[tool.ruff.lint.per-file-ignores]
Expand Down

0 comments on commit 556ae16

Please sign in to comment.