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

Exclude UP007 from Ruff Config, i.e. prefer Optional[T] over T | None #336

Closed
alexjbuck opened this issue Dec 19, 2023 · 1 comment
Closed
Assignees

Comments

@alexjbuck
Copy link
Contributor

See title. Linter rule UP007 tries to change Optional[T] into T | None and I think that the Optional[T] syntax is better. This is a residual from before Optional was possible.

The rule was originally to detect Union[T,None] and recommend T | None. I concur that T | None is better than using Union but Optional should be preferred to both. Until the linter rule is updated (there is an issue about this topic here) I recommend we add UP007 to our exclude list.

@alexjbuck
Copy link
Contributor Author

Refer to discussion in #337. Closing issue for now. Keeping the rule enabled results in one valid way to write the type hint in question, disabling the rule results in three valid ways to write it.

T | None is the path forward until UP007 can be amended to account for Optional[T] patterns.

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

1 participant