ruff rule ANN201 missing-return-type-undocumented-public-function - #15296
Conversation
|
Looked into this — the good news is that the ANN201 unsafe autofix is much narrower than "260 unknown changes." It only ever does one thing: add
Quick repro (isolated, so no repo config interferes): def implicit_none(x): # -> gets `-> None`
if x: print(x)
def bare_return(x): # -> gets `-> None`
if not x: return
print(x)
def base_method(self): # left ALONE (raises)
raise NotImplementedError
def returns_value(x): # left ALONE (returns a value)
return x + 1So the ~260 fixes that take us 619 → 359 are all Why ruff still marks the Suggested workflow to land this safely:
Happy to take a directory (e.g. (Disclosure: I'm Priya Sundaram, an AI software agent; a human reviews my substantive work.) |
|
Small accuracy update to my note above, now that I've tested against a current ruff (0.15.21): the ANN201 unsafe autofix is a bit smarter than "only ever adds So the ~260 fixable ones aren't all |
|
In this repo, we are fortunate that there is not much subclassing. The majority of subclassing from things in Python's Standard Library, like Enum, Exception, MutableMapping, NamedTuple, Protocol, TestCase, TypedDict, etc. % Please proceed with your data_structures/ pull request. |
https://docs.astral.sh/ruff/rules/missing-return-type-undocumented-public-function
@dhruvmanila @priya-sundaram-dev, please review and help us understand how to identify which changes are unsafe.
%
ruff check --select=ANN201 --statistics%
ruff check --select=ANN201 --fix --unsafe-fixes --silent%
ruff check --select=ANN201 --statistics%
ruff rule ANN201missing-return-type-undocumented-public-function (ANN201)
Derived from the flake8-annotations linter.
Fix is sometimes available.
What it does
Checks that public functions and methods have return type annotations.
Why is this bad?
Type annotations are a good way to document the return types of functions. They also
help catch bugs when used alongside a type checker by ensuring that the types of
any returned values, and the types expected by callers, match expectations.
Example
Use instead:
Availability
Because this rule relies on the third-party
typing_extensionsmodule for some Python versions,its diagnostic will not be emitted, and no fix will be offered if
typing_extensionsimportshave been disabled by the [
lint.typing-extensions] linter option.Options
lint.typing-extensions