Mypy run reveals a bunch of type errors
shakfu opened this issue · 4 comments
Hi,
Cool project by the way.
I was messing around with my fork of your project (not many changes mostly just running black and a couple of tweaks), and the I ran mypy:
mypy src
and I got the following (I fixed a couple, so this list should be a little longer on your version). I definitely recommend checking this out since you need to have rigor in your type system and vs code doesn't pick up on these.
src/cfile/core.py:469: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
src/cfile/core.py:477: error: Item "Comment" of "Comment | Statement | Sequence" has no attribute "append" [union-attr]
src/cfile/core.py:477: error: Item "Statement" of "Comment | Statement | Sequence" has no attribute "append" [union-attr]
src/cfile/core.py:484: error: Item "Comment" of "Comment | Statement | Sequence" has no attribute "extend" [union-attr]
src/cfile/core.py:484: error: Item "Statement" of "Comment | Statement | Sequence" has no attribute "extend" [union-attr]
src/cfile/writer.py:34: error: Incompatible types in assignment (expression has type "None", variable has type "str") [assignment]
src/cfile/writer.py:35: error: Incompatible types in assignment (expression has type "None", variable has type "TextIO") [assignment]
src/cfile/writer.py:141: error: "TextIO" has no attribute "getvalue" [attr-defined]
src/cfile/writer.py:148: error: "TextIO" has no attribute "getvalue" [attr-defined]
src/cfile/writer.py:155: error: Cannot call function of unknown type [operator]
src/cfile/writer.py:162: error: Item "Comment" of "Comment | Statement | Sequence" has no attribute "__iter__" (not iterable) [union-attr]
src/cfile/writer.py:162: error: Item "Statement" of "Comment | Statement | Sequence" has no attribute "__iter__" (not iterable) [union-attr]
src/cfile/writer.py:162: error: Item "Sequence" of "Comment | Statement | Sequence" has no attribute "__iter__" (not iterable) [union-attr]
src/cfile/writer.py:189: error: Cannot call function of unknown type [operator]
src/cfile/writer.py:212: error: Cannot call function of unknown type [operator]
src/cfile/writer.py:317: error: Argument 1 to "_write_type" of "Writer" has incompatible type "Type | Struct"; expected "Type | StructRef" [arg-type]
src/cfile/writer.py:341: error: Item "Struct" of "Type | Struct" has no attribute "pointer" [union-attr]
src/cfile/writer.py:351: error: Item "Struct" of "Type | Struct" has no attribute "pointer" [union-attr]
src/cfile/writer.py:437: error: Argument 1 to "len" has incompatible type "Comment | Statement | Sequence"; expected "Sized" [arg-type]
src/cfile/factory.py:34: error: Incompatible return value type (got "Line", expected "Blank") [return-value]
src/cfile/factory.py:99: error: Invalid type comment or annotation [valid-type]
src/cfile/factory.py:99: note: Suggestion: use core.Block[...] instead of core.Block(...)
src/cfile/factory.py:114: error: Argument 2 to "Function" has incompatible type "str | Type | Struct | None"; expected "str | Type | None" [arg-type]
src/cfile/factory.py:126: error: Argument 1 to "Type" has incompatible type "str | Type | Struct"; expected "str | Type" [arg-type]
Found 22 errors in 3 files (checked 5 source files)
Thanks for the feedback, I will try to check against mypy in the future.
Currently I'm doing a major refactoring of the code due to a fundamental design issue I found a while back.
It's going to take some time to get it fixed.
Sounds good. Happy to provide feedback if required.
I fixed as much as I could. The remaining issue I believe is some bug in mypy. Perhaps I'll find a workaround for it later.
Sounds good!