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

[ruff] Do not report when Optional has no type arguments (RUF013) #14181

Merged
merged 5 commits into from
Nov 9, 2024

Conversation

InSyncWithFoo
Copy link
Contributor

Summary

Resolves #13833.

Test Plan

cargo nextest run and cargo insta test.

Copy link
Contributor

github-actions bot commented Nov 8, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser added the rule Implementing or modifying a lint rule label Nov 8, 2024
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you for looking into this issue.

The check looks good to me, but I think we should move it into type_hint_explicitly_allows_none so that Annotated[Optional, "bla"] also works

@charliermarsh charliermarsh added bug Something isn't working and removed rule Implementing or modifying a lint rule labels Nov 9, 2024
@charliermarsh charliermarsh merged commit c9b84e2 into astral-sh:main Nov 9, 2024
20 checks passed
@henryiii
Copy link
Contributor

henryiii commented Nov 9, 2024

I'm confused, bare Optional still isn't a valid type annotation for type checkers, isn't it? Optional would be Optional[Any], which expands to Union[None, Any], but a Union with Any is just Any. I thought the problem was the suggested fix, Optional[Optional] was nonsense. Optional[Any] would make more sense and I believe type checkers are okay with that (even if it's no different than just Any).

@charliermarsh
Copy link
Member

That’s correct but seems outside the scope of the rule? Like a bare Optional being invalid should be its own rule.

@henryiii
Copy link
Contributor

henryiii commented Nov 9, 2024

Ah, yes, that makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RUF013 incorrectly emitted on invalid annotation with bare Optional
4 participants