New rule for checking that a str is not assigned the variable None (at initialization) #4456
Replies: 3 comments
-
I appreciate your willingness to implement this yourself, that is awesome :) The challenge with an autofix here is that the "correct" fix is ambiguous. E.g., I think the "correct" fix would more often (but not always) be |
Beta Was this translation helpful? Give feedback.
-
I looked through https://peps.python.org/pep-0484/ and it looks like it was implemented in python 3.5
Ruff itself only supports 3.7 and above and according to google 3.7 was released in So I assume that people using Ruff, would be using a version of 3.7 that is compatible with the proposed autofix. I assume for compatibility sakes in the code it would still be better if the autofix made the optional behaviour of the variable explicit and then it would be up to the person to change it from an optional themselves. Will try working on this soon. Just wanted to give more context to the change. |
Beta Was this translation helpful? Give feedback.
-
It looks like this rule as been implemented since the time we talked about it as the Thanks for your hard work, will close down this issue (and maybe look for some other rule to work on) |
Beta Was this translation helpful? Give feedback.
-
So I, myself, have the habit of doing
foo: str = None
which has been advised against.I don't plan on adding more work to the mantainers, so I will implement the Rule myself, the Ruff Rule I propose is initially
and it should allow auto-fixing to:
This could be improved upon with new rules later but let's keep it simple.
If I get the approval of the maintainers I shall start working on this,
Beta Was this translation helpful? Give feedback.
All reactions