guilatrova / tryceratops

A linter to prevent exception handling antipatterns in Python (limited only for those who like dinosaurs).

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mypy raises many warnings

MaxG87 opened this issue · comments

I ran mypy against the codebase. I got 38 warnings, albeit I admit that my mypy settings are rather strict.

From my experience fixing mypy issues helps to catch subtle and not-so-subtle bugs. Thus I think having detectable type violations is a sign that something is odd.

For convenience I post the list that was detected below. I think tackling these one by one could be beneficial.

src/tests/samples/violations/except_verbose_reraise.py:23: error: Name "func" already defined on line 12
src/tests/samples/violations/call_check_continue.py:21: error: Return value expected
src/tryceratops/analyzers/base.py:18: error: Method must have at least one argument
src/tryceratops/analyzers/base.py:29: error: "BaseAnalyzer" has no attribute "visit"
src/tryceratops/analyzers/try_block.py:29: error: Incompatible types in "yield from" (actual type "AST", expected type "stmt")
src/tryceratops/analyzers/exception_block.py:18: error: Argument 1 to "is_raise_without_cause" has incompatible type "AST"; expected "stmt"
src/tryceratops/analyzers/exception_block.py:38: error: Argument 1 to "is_raise_with_name" has incompatible type "AST"; expected "stmt"
src/tryceratops/analyzers/exception_block.py:54: error: Argument 1 to "_is_vanilla_exception" of "ExceptBroadPassAnalyzer" has incompatible type "Name"; expected "stmt"
src/tryceratops/analyzers/exception_block.py:58: error: Argument 1 to "_is_vanilla_exception" of "ExceptBroadPassAnalyzer" has incompatible type "expr"; expected "stmt"
src/tryceratops/analyzers/call.py:42: error: "expr" has no attribute "value"
src/tryceratops/analyzers/call.py:61: error: "expr" has no attribute "id"
src/tryceratops/analyzers/call.py:67: error: "stmt" has no attribute "targets"
src/tryceratops/analyzers/call.py:82: error: Argument 1 to "is_if_returning" has incompatible type "StmtBodyProtocol"; expected "stmt"
src/tryceratops/analyzers/call.py:83: error: Argument 1 to "append" of "list" has incompatible type "StmtBodyProtocol"; expected "stmt"
src/tryceratops/analyzers/call.py:86: error: "stmt" has no attribute "test"
src/tryceratops/analyzers/call.py:89: error: "expr" has no attribute "func"
src/tryceratops/analyzers/call.py:90: error: "expr" has no attribute "func"
src/tryceratops/analyzers/call.py:98: error: "expr" has no attribute "func"
src/tryceratops/analyzers/call.py:99: error: "expr" has no attribute "func"
src/tryceratops/analyzers/call.py:124: error: Argument 1 to "_scan_deeper" of "CallAvoidCheckingToContinueAnalyzer" has incompatible type "stmt"; expected "StmtBodyProtocol"
src/tryceratops/filters.py:69: error: "def () -> Tuple[builtins.str, builtins.str]" object is not iterable
src/tryceratops/filters.py:70: error: Cannot determine type of "code"
src/tryceratops/filters.py:70: error: Unsupported right operand type for in ("Optional[Iterable[str]]")
src/tryceratops/filters.py:79: error: Item "None" of "Optional[Iterable[str]]" has no attribute "__iter__" (not iterable)
src/tryceratops/analyzers/main.py:32: error: Cannot instantiate abstract class "BaseAnalyzer" with abstract attribute "violation_code"
src/tryceratops/analyzers/main.py:34: error: Only concrete class can be given where "Type[BaseAnalyzer]" is expected
src/tryceratops/analyzers/main.py:61: error: Argument 1 to "len" has incompatible type "Iterable[Tuple[str, AST, FileFilter]]"; expected "Sized"
src/tryceratops/files/parser.py:45: error: Argument 1 to "parse_tree" has incompatible type "TextIO"; expected "TextIOWrapper"
src/tryceratops/files/parser.py:48: error: Argument 1 to "parse_ignore_comments_from_file" has incompatible type "TextIO"; expected "TextIOWrapper"
src/tests/fuzztests.py:10: error: Missing positional argument "global_filter" in call to "analyze" of "Runner"
src/tryceratops/files/discovery.py:2: error: Library stubs not installed for "toml" (or incompatible with Python 3.9)
src/tryceratops/files/discovery.py:2: note: Hint: "python3 -m pip install types-toml"
src/tryceratops/files/discovery.py:2: note: (or run "mypy --install-types" to install all missing stub packages)
src/tryceratops/files/discovery.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
src/tryceratops/files/discovery.py:50: error: Incompatible types in assignment (expression has type "Generator[str, None, None]", variable has type "List[str]")
src/tryceratops/files/discovery.py:103: error: Missing return statement
src/tryceratops/files/discovery.py:111: error: Missing return statement
src/tryceratops/files/discovery.py:112: error: Argument 1 to "find_pyproject_toml" has incompatible type "Sequence[str]"; expected "Tuple[str, ...]"
src/tryceratops/flake_plugin.py:32: error: Argument 1 to "parse_ignore_tokens" has incompatible type "Optional[Iterable[TokenInfo]]"; expected "Iterable[TokenInfo]"
src/tryceratops/flake_plugin.py:34: error: Argument 1 to "_create_global_filter" of "TryceratopsAdapterPlugin" has incompatible type "Optional[str]"; expected "str"
src/tryceratops/flake_plugin.py:51: error: Argument 1 to "analyze" of "Runner" has incompatible type "List[Tuple[Optional[str], AST, FileFilter]]"; expected "Iterable[Tuple[str, AST, FileFilter]]"
Found 38 errors in 12 files (checked 38 source files)

You're correct! How can we claim we're a linter if we don't even lint ourselves? haha

Thanks for the push. I'll try to take the time to solve that by the end of this week, this card is in the roadmap already, but hey,

Don't wait for me!

This project is ours ❤️
if you @MaxG87 or anyone else has some time and are willing to contribute, please, go for it!

I just ask to follow the conventional commits standard.

I'll resolve this issue soon! 😁

I resolved just part of it and ignored some files.
I'd appreciate help from anyone in case interested :)