Rule: Auto-add -> None typehint to functions#8212
Rule: Auto-add -> None typehint to functions#8212intgr wants to merge 2 commits intoastral-sh:mainfrom
-> None typehint to functions#8212Conversation
-> None typehint to functions
|
Also some relevant points here that I should consider: |
|
I haven't had a chance to review the code yet, but I think we could just treat this as a sometimes-available autofix for |
Just be aware that it's very incomplete and broken right now.
I see where you're coming from. My initial thoughts:
But I'm by no means committed to this approach. |
|
I ended up adding a similar fix for the ANN rules as a fun Sunday-night hack: #8643. It won't apply to functions that already have annotations as you mention, but the logic does extend to other primitive types and unions of those types. |

Summary
WIP: This is a very early partial draft still. No need to do serious review yet, but feel free to give me pointers.
I want to create a new Ruff rule that auto-adds
-> Nonereturn type hint to functions when noreturn <value>statements are present in the function.Clearly there are lots of special cases I need to handle (
yield,raise,@overload,.pyifiles, etc).I currently used rule code
RUF300, which is unprecedented. But I think it may make sense to allocate a specific RUF range for typehinting-related rules. I have a few more ideas similar to this one.-> Nonetypehint to functions #8213Test Plan
TBD.