crytic / amarna

Amarna is a static-analyzer and linter for the Cairo programming language.
https://blog.trailofbits.com/2022/04/20/amarna-static-analysis-for-cairo-programs/
GNU Affero General Public License v3.0
149 stars 7 forks source link

Add type hints #5

Closed montyly closed 2 years ago

montyly commented 2 years ago

Add types hints everywhere, checked mypy 0.942 (mypy --config mypy.ini amarna). The only remaining warnings are for

amarna/rules/local_rules/UnusedImportRule.py:60: error: Unsupported operand types for + ("str" and "Tree[Any]")
amarna/rules/local_rules/UnusedImportRule.py:60: note: Right operand is of type "Union[Any, Tree[Any]]"
amarna/rules/local_rules/UnusedImportRule.py:65: error: Item "Tree[Any]" of "Union[Any, Tree[Any]]" has no attribute "value"
amarna/rules/local_rules/UnusedImportRule.py:76: error: Item "Tree[Any]" of "Union[Any, Tree[Any]]" has no attribute "line"
amarna/rules/local_rules/UnusedImportRule.py:76: error: Item "Tree[Any]" of "Union[Any, Tree[Any]]" has no attribute "column"
amarna/rules/local_rules/UnusedImportRule.py:76: error: Item "Tree[Any]" of "Union[Any, Tree[Any]]" has no attribute "end_line"
amarna/rules/local_rules/UnusedImportRule.py:76: error: Item "Tree[Any]" of "Union[Any, Tree[Any]]" has no attribute "end_column"

But I am a bit unsure about the types for all_hints and unused_imports there

Additionally, there were a lot of places where # type: ignore was needed, mostly due to patterns like children_id.children[0].value, where mypy can't understand the underlying type. I am not too familiar with lark, but the documentation mentions type annotation support, so we might be able to improve this.

Built on top of #3 and #4