-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
UP007: opt out of Optional #4858
Comments
A third option would be to add a setting to retain |
Just adding my voice to agree with this. It appears that most people are either in favour of or indifferent to Breaking it up into two rules (or perhaps even three, leaving |
I personally don't have a preference for
Not challenging this, but is this based on data? Like a survey or something? Or your own experiences and interactions? |
Not based on a formal survey, just based on asking other developers what they think |
What if UP007 became a way to just enable both of the split out rules + write a deprecation warning? I'm not too worried about the edge case where someone has |
Whose decision is this waiting on? I think the first solution is the least disruptive and I would also like to see this rule split between In my opinion |
Sure. Someone can do this if they want:
I'm not too concerned about people ignoring |
But it isn't: Optional means the parameter may be None, not that it is optional. A parameter can be optional (i.e., have a default) without having an Optional type, and vice versa. This is actually one of the main reasons from my perspective why Optional should be avoided: its name is misleading. |
Perhaps |
See <https://docs.astral.sh/ruff/rules/non-pep604-annotation/> Also this comment is quite clear on why doing this: <astral-sh/ruff#4858 (comment)>
See <https://docs.astral.sh/ruff/rules/non-pep604-annotation/> Also this comment is quite clear on why doing this: <astral-sh/ruff#4858 (comment)>
Hello, currently UP007 covers both
Union[a, b, c]
->a | b | c
andOptional[a]
->a | None
.Personally i find Optional to be more readable and PEP 604 does not deprecate this syntax either.
I'm not sure how it could be changed without breaking changes. I see 2 ways:
UP007
stops reporting Optional, keeps reporting Union and later added rulesUP039
is added which only reports OptionalThe downside of this is that it forces people to update config to get previous behavior if they didn't have entire
UP
category enabled. Alternative is:UP007
remains unchangedUP039
is added which reports Union and later added rulesThis might be even worse because
UP
in config it does double workUP
enabled andUP007
ignored, the Union lint would reappear (although I'd assume most people who do this because of Optional)pyupgrade author made it clear in multiple issues that they are not going to change this asottile/pyupgrade#390 (comment). don't know how much you are willing to deviate from "upstream" for cases like this but it would be a nice addition
The text was updated successfully, but these errors were encountered: