Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop flake8-noqa and remove workarounds to work with Ruff #13571

Merged
merged 6 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
[flake8]
# NQA: Ruff won't warn about redundant `# noqa: Y`
# Y: Flake8 is only used to run flake8-pyi, everything else is in Ruff
# F821: Typeshed is a testing ground for flake8-pyi, which monkeypatches F821
select = NQA, Y, F821
select = Y, F821
# Ignore rules normally excluded by default
extend-ignore = Y090
per-file-ignores =
# We should only need to noqa Y and F821 codes in .pyi files
*.py: NQA
# Generated protobuf files:
# Y021: Include docstrings
# Y023: Alias typing as typing_extensions
Expand All @@ -16,4 +13,3 @@ per-file-ignores =
stubs/*_pb2.pyi: Y021, Y023, Y026, Y053

exclude = .venv*,.git
noqa_require_code = true
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,11 @@ repos:
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
rev: 7.1.2
hooks:
- id: flake8
language: python
additional_dependencies:
- "flake8-noqa==1.4.0"
- "flake8-pyi==24.9.0"
types: [file]
types_or: [python, pyi]
Expand Down
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ it takes a bit longer. For more details, read below.

Typeshed runs continuous integration (CI) on all pull requests. This means that
if you file a pull request (PR), our full test suite
-- including our linter, [Flake8](https://github.com/PyCQA/flake8) --
-- including our linter, [`flake8-pyi`](https://github.com/pycqa/flake8-pyi) --
is run on your PR. It also means that bots will automatically apply
changes to your PR (using [Black](https://github.com/psf/black) and
[Ruff](https://github.com/astral-sh/ruff)) to fix any formatting issues.
Expand Down Expand Up @@ -88,8 +88,7 @@ The code is formatted using [`Black`](https://github.com/psf/black).
Various other autofixes and lint rules are
also performed by [`Ruff`](https://github.com/astral-sh/ruff) and
[`Flake8`](https://github.com/pycqa/flake8),
with plugins [`flake8-pyi`](https://github.com/pycqa/flake8-pyi),
and [`flake8-noqa`](https://github.com/plinss/flake8-noqa).
with plugin [`flake8-pyi`](https://github.com/pycqa/flake8-pyi).

The repository is equipped with a [pre-commit.ci](https://pre-commit.ci/)
configuration file. This means that you don't *need* to do anything yourself to
Expand Down
8 changes: 3 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ exclude = [
# are invoked via separate runs of ruff in pre-commit:
# see our .pre-commit-config.yaml file for details
exclude = ["**/test_cases/**/*.py"]
# We still use flake8-pyi and flake8-noqa to check these (see .flake8 config file);
# We still use flake8-pyi to check these (see .flake8 config file);
# tell ruff not to flag these as e.g. "unused noqa comments"
external = ["F821", "NQA", "Y"]
external = ["F821", "Y"]
select = [
"ARG", # flake8-unused-arguments
"B", # flake8-bugbear
Expand Down Expand Up @@ -66,8 +66,7 @@ select = [
"FURB177", # Prefer `Path.cwd()` over `Path().resolve()` for current-directory lookups
"FURB187", # Use of assignment of `reversed` on list `{name}`
# PYI: only enable rules that have autofixes and that we always want to fix (even manually),
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate PR (or this one if you prefer), this could be changed to

Suggested change
# PYI: only enable rules that have autofixes and that we always want to fix (even manually),
# PYI: only enable rules for which we never noqa their flake8-pyi plugin equivalent,

Even better imo is to instead select all and disable the few codes where this happens.

# avoids duplicate # noqa with flake8-pyi and flake8-noqa flagging `PYI` codes
# See https://github.com/plinss/flake8-noqa/issues/22
# avoids duplicate # noqa with flake8-pyi
"PYI009", # Empty body should contain `...`, not pass
"PYI010", # Function body must contain only `...`
"PYI012", # Class bodies must not contain `pass`
Expand All @@ -81,7 +80,6 @@ select = [
# "PYI026", Waiting for this mypy bug to be fixed: https://github.com/python/mypy/issues/16581
"PYI030", # Multiple literal members in a union. Use a single literal, e.g. `Literal[{}]`
"PYI032", # Prefer `object` to `Any` for the second parameter to `{method_name}`
"PYI034", # `__new__` methods usually return self at runtime
"PYI036", # Star-args in `{method_name}` should be annotated with `object`
"PYI044", # `from __future__ import annotations` has no effect in stub files, since type checkers automatically treat stubs as having those semantics
"PYI055", # Multiple `type[T]` usages in a union. Combine them into one, e.g., `type[{union_str}]`.
Expand Down
7 changes: 5 additions & 2 deletions stdlib/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# ruff: noqa: PYI036 # This is the module declaring BaseException
import _ast
import _sitebuiltins
import _typeshed
Expand Down Expand Up @@ -870,7 +869,11 @@ class memoryview(Sequence[_I]):
def __new__(cls, obj: ReadableBuffer) -> Self: ...
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None, /
self,
exc_type: type[BaseException] | None, # noqa: PYI036 # This is the module declaring BaseException
exc_val: BaseException | None,
exc_tb: TracebackType | None,
/,
) -> None: ...
@overload
def cast(self, format: Literal["c", "@c"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bytes]: ...
Expand Down
3 changes: 1 addition & 2 deletions stdlib/typing_extensions.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
# ruff: noqa: PYI034
import abc
import sys
import typing
Expand Down Expand Up @@ -251,6 +249,7 @@ class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
@overload
def __ror__(self, value: dict[str, Any], /) -> dict[str, object]: ...
# supposedly incompatible definitions of `__ior__` and `__or__`:
# Since this module defines "Self" it is not recognized by Ruff as typing_extensions.Self
def __ior__(self, value: Self, /) -> Self: ... # type: ignore[misc]

OrderedDict = _Alias()
Expand Down
4 changes: 1 addition & 3 deletions stubs/boltons/boltons/dictutils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ class FrozenDict(dict[_KT, _VT]):
@classmethod
def fromkeys(cls, keys: Iterable[_KT], value: _VT | None = None) -> Self: ... # type: ignore[override]
def updated(self, *a, **kw) -> Self: ...
# Can't noqa because of https://github.com/plinss/flake8-noqa/pull/30
# Signature conflicts with superclass, so let's just omit it
# def __ior__(self, *a, **kw) -> NoReturn: ...
def __ior__(self, *a, **kw) -> NoReturn: ... # type: ignore[misc] # noqa: Y034 # Signature conflicts with superclass
def __setitem__(self, *a, **kw) -> NoReturn: ...
def __delitem__(self, *a, **kw) -> NoReturn: ...
def update(self, *a, **kw) -> NoReturn: ...
Expand Down
3 changes: 0 additions & 3 deletions stubs/geopandas/geopandas/io/sql.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ from pandas._typing import Scalar
from ..base import _ConvertibleToCRS
from ..geodataframe import GeoDataFrame

# inline ruff noqa at _SqlalchemyConnectionLike.__enter__ confuses flake8
# ruff: noqa: PYI034

# Start SQLAlchemy hack
# ---------------------
# The code actually explicitly checks for SQLAlchemy's `Connection` and `Engine` with
Expand Down
1 change: 0 additions & 1 deletion stubs/six/six/moves/builtins.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa: NQA102 # https://github.com/plinss/flake8-noqa/issues/22
# six explicitly re-exports builtins. Normally this is something we'd want to avoid.
# But this is specifically a compatibility package.
from builtins import * # noqa: UP029