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

RUF013 incorrectly emitted on invalid annotation with bare Optional #13833

Closed
Skylion007 opened this issue Oct 20, 2024 · 2 comments · Fixed by #14181
Closed

RUF013 incorrectly emitted on invalid annotation with bare Optional #13833

Skylion007 opened this issue Oct 20, 2024 · 2 comments · Fixed by #14181
Labels
bug Something isn't working

Comments

@Skylion007
Copy link
Contributor

Skylion007 commented Oct 20, 2024

Here is the bad code diff

-        hsdp_device_mesh: Optional = None,
+        hsdp_device_mesh: Optional[Optional] = None,

Obviously, an untyped Optional is fine, and Optional[Optional] doesn't make much sense here as an autofix.

  • version ruff 0.7.0
  • ruff check RUF013 --select=RUF013 . --fix --unsafe-fixes
@AlexWaygood
Copy link
Member

A bare Optional is not a valid type annotation; both mypy and pyright will reject using Optional without type arguments in an annotation:

But you're right that the autofix here just makes things worse! I think we should just not emit RUF013 at all here. It's outside the scope of this rule to detect type annotations that are simply invalid, and definitely outside the scope of the rule to try to fix them.

@AlexWaygood AlexWaygood added the bug Something isn't working label Oct 20, 2024
@AlexWaygood AlexWaygood changed the title Autofix bug with RUF013 RUF013 incorrectly emitted on invalid annotation with bare Optional Oct 20, 2024
@henryiii
Copy link
Contributor

A bare Optional would be Optional[Any], which is Any | None. Which isn't helpful, since Any already includes None. The ones that are allowed to be bare, like list -> list[Any], still make sense with Any.

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 a pull request may close this issue.

3 participants