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

Use Ruff, fix various tests #92

Merged
merged 7 commits into from
Feb 13, 2024
Merged

Use Ruff, fix various tests #92

merged 7 commits into from
Feb 13, 2024

Conversation

JelleZijlstra
Copy link
Owner

No description provided.

@AlexWaygood
Copy link
Contributor

AlexWaygood commented Feb 13, 2024

You could consider adding RUF021, since you suggested it ;)

But it's still in preview, so I think you'd have to add preview = true to tool.ruff.lint in your pyproject.toml

@JelleZijlstra
Copy link
Owner Author

I added the whole RUF series because why not. I really like RUF005; that's something I've often done manually.

@JelleZijlstra
Copy link
Owner Author

Though come to think of it I should probably refactor that code that RUF005 changed since it deals with the old typeshed layout.

@AlexWaygood
Copy link
Contributor

AlexWaygood commented Feb 13, 2024

I added the whole RUF series because why not. I really like RUF005; that's something I've often done manually.

Funny, that's one of only two RUF one I have disabled in my config for typeshed-stats 😄 I'm not sure it always leads to faster code. But YMMV :)

The other RUF one I disable is RUF013 (because mypy already enforces that), and I disable the autofix for RUF017 (ruff chooses the fastest autofix, which uses functools.reduce and operator.iadd, but I prefer itertools.chain.from_iterable, which is only a tiny bit slower and looks much cleaner IMO)

ignore = [
"ANN101", # missing type annotation for self in method
"ANN102", # missing type annotation for cls in classmethod
"SIM105", # I don't like contextlib.suppress
Copy link
Contributor

Choose a reason for hiding this comment

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

I always ignore UP038 because of astral-sh/ruff#7871, though it doesn't make much of a difference here since the rule only does things if your lowest supported version is Python 3.10

Copy link
Owner Author

Choose a reason for hiding this comment

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

Yeah I agree with you there, adding support for isinstance() with UnionType was a questionable design choice in the first place. I'll add it to the exclude list and see if I still agree in two years' time when 3.9 goes EOL :)

@JelleZijlstra
Copy link
Owner Author

As for RUF005, I don't really care if it's marginally faster (if it's slower, just complain to Brandt :P), but I feel it makes the code look cleaner.

What's the disadvantage in having RUF013 on even if mypy also enforces it?

@AlexWaygood
Copy link
Contributor

AlexWaygood commented Feb 13, 2024

What's the disadvantage in having RUF013 on even if mypy also enforces it?

No real disadvantage, just my personal preference -- I just prefer to have the type checker complain about my types and ruff focus on other stuff :)

@JelleZijlstra JelleZijlstra merged commit 5fcf786 into master Feb 13, 2024
12 checks passed
@JelleZijlstra JelleZijlstra deleted the update branch February 13, 2024 16:15
@JelleZijlstra JelleZijlstra restored the update branch September 10, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants