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

Enable more Ruff PYI rules with autofixes #12557

Merged
merged 3 commits into from
Sep 4, 2024

Conversation

Avasam
Copy link
Collaborator

@Avasam Avasam commented Aug 19, 2024

Added rules: PYI014, PYI015, PYI030, PYI036, PYI044, PYI062

I originally split this into 3 sections (Fix is always available., Fix is sometimes available., and We sometimes noqa these), but I'm not sure if that's something worth doing, keeping it here for archiving purposes:

select = [
    ...

	# PYI rules that sometimes autofix, but we should always be able to manually fix,
	# so there's still no conflict/duplicate with flake8-pyi
	"PYI013", # Non-empty class bodies must not contain `...`
	"PYI016", # Duplicate union member `{}`
	"PYI025", # Use `from collections.abc import Set as AbstractSet` to avoid confusion with the `set` builtin
	"PYI030", # Multiple literal members in a union. Use a single literal, e.g. `Literal[{}]`
	"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}]`.
	"PYI062", # Duplicate literal member `{}`
	# Rules that have autofixes, but we sometimes disable on a per-line basis
	# "PYI026", Waiting for this mypy bug to be fixed: https://github.com/python/mypy/issues/16581
	# "PYI029", __str__ and __str__ sometimes have to be used for classes other than `object`
	# Sometimes we still wanna be explicit about a default value nonetheless
	# "PYI011",
	# "PYI053", Also removes `Literal[{string_too_long}]` from an annotation
	# "PYI054",
]

This comment has been minimized.

pyproject.toml Outdated
# "PYI029", __str__ and __str__ sometimes have to be used for classes other than `object`
# Sometimes we still wanna be explicit about a default value nonetheless
# "PYI011", Also has false-positives with `_typeshed.sentinel`
# "PYI053", Also removes `Literal[{string_too_long}]` from an annotation
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We noqa that one twice in nanoid stubs for the paramether alphabet: str = "_-0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

Ruff issue for the bad autofix in Literal: astral-sh/ruff#12995

@Avasam Avasam added the project: infrastructure typeshed build, test, documentation, or distribution related label Aug 20, 2024
@sobolevn sobolevn requested a review from AlexWaygood August 20, 2024 19:31
Comment on lines +50 to 51
# avoids duplicate # noqa with flake8-pyi and flake8-noqa flagging `PYI` codes
# See https://github.com/plinss/flake8-noqa/issues/22
Copy link
Collaborator Author

@Avasam Avasam Aug 21, 2024

Choose a reason for hiding this comment

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

If anyone has a contact to @plinss , plinss/flake8-noqa#30 would be a nice flake8-noqa feature to get merged ^^"

@Avasam
Copy link
Collaborator Author

Avasam commented Aug 22, 2024

Doesn't look like Ruff 0.6.2 added anything that should affect this (PYI053 has less false-positives, but it's still disabled on our side)

Copy link
Contributor

github-actions bot commented Sep 4, 2024

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@Avasam
Copy link
Collaborator Author

Avasam commented Sep 4, 2024

Jelle approved 2 weeks ago and it's unchallenged. I'll merge it. If you see an issue, open a new PR!

@Avasam Avasam merged commit 89e0b69 into python:main Sep 4, 2024
68 checks passed
@Avasam Avasam deleted the ruff-add-more-autofixes-rules branch September 4, 2024 23:50
max-muoto pushed a commit to max-muoto/typeshed that referenced this pull request Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
project: infrastructure typeshed build, test, documentation, or distribution related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants