Closed rytilahti closed 1 year ago
Yeah I'd love to do this. I want to add a couple autofixes for typing-related stuff and this is a good candidate.
I think this is a good rule to add along with the auto-fix ability. Should this be added under the RUF
or ANN
category? I'm leaning towards RUF
. I can take this on.
I've started working on this
Recent mypy versions have started to warn about implicit optionals on function signatures, which has been prohibited by pep 484 since https://github.com/python/peps/pull/689. It would be great if ruff would spot and fix this automatically for you, considering how easy it is to forget to do this while coding.
Minimal code example:
mypy
output:The fix for python3.10 and newer would be modifying the definition to be:
On the implementation side, I think this would belong to flake8-annotations but as it isn't checking for this, I'm wondering what would be the correct place to implement this?
For older Python versions the fix would require either
from __future__ import annotations
orfrom typing import Optional
and usingoptional: Optional[str]
, both of which might be too invasive for automated fixing.