Skip to content

Stricter Line Count Report #17809

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions mypy/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from mypy.nodes import Expression, FuncDef, MypyFile
from mypy.options import Options
from mypy.traverser import TraverserVisitor
from mypy.types import Type, TypeOfAny
from mypy.types import AnyType, CallableType, ProperType, Type, TypeOfAny, get_proper_type
from mypy.version import __version__

try:
Expand Down Expand Up @@ -154,7 +154,25 @@ def __init__(self) -> None:
self.counts = [0, 0]

def visit_func_def(self, defn: FuncDef) -> None:
self.counts[defn.type is not None] += 1
def is_unannotated_any(t: Type) -> bool:
if not isinstance(t, ProperType):
return False
return isinstance(t, AnyType) and t.type_of_any == TypeOfAny.unannotated

if defn.type is None:
self.counts[0] += 1
return
elif isinstance(defn.type, CallableType):
ret_type = get_proper_type(defn.type.ret_type)
if is_unannotated_any(ret_type):
self.counts[0] += 1
return
# TODO: Add check to handle generators and co-routines
if any(is_unannotated_any(t) for t in defn.type.arg_types):
self.counts[0] += 1
return

self.counts[1] += 1


class LineCountReporter(AbstractReporter):
Expand Down
Loading