microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
29 stars 5 forks source link

mypy generates lots of warnings on generated code #97

Closed KrisThielemans closed 7 months ago

KrisThielemans commented 8 months ago

For instance, on https://github.com/ETSInitiative/PRDdefinition/tree/main/python

$ mypy prd_generator.py 
prd/yardl_types.py:270: error: No overload variant of "zip" matches argument types "void", "void"  [call-overload]
prd/yardl_types.py:270: note: Possible overload variants:
prd/yardl_types.py:270: note:     def [_T_co, _T1] __new__(cls, Iterable[_T1], /, *, strict: bool = ...) -> zip[tuple[_T1]]
prd/yardl_types.py:270: note:     def [_T_co, _T1, _T2] __new__(cls, Iterable[_T1], Iterable[_T2], /, *, strict: bool = ...) -> zip[tuple[_T1, _T2]]
prd/yardl_types.py:270: note:     def [_T_co, _T1, _T2, _T3] __new__(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], /, *, strict: bool = ...) -> zip[tuple[_T1, _T2, _T3]]
prd/yardl_types.py:270: note:     def [_T_co, _T1, _T2, _T3, _T4] __new__(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], /, *, strict: bool = ...) -> zip[tuple[_T1, _T2, _T3, _T4]]
prd/yardl_types.py:270: note:     def [_T_co, _T1, _T2, _T3, _T4, _T5] __new__(cls, Iterable[_T1], Iterable[_T2], Iterable[_T3], Iterable[_T4], Iterable[_T5], /, *, strict: bool = ...) -> zip[tuple[_T1, _T2, _T3, _T4, _T5]]
prd/yardl_types.py:270: note:     def [_T_co] __new__(cls, Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], Iterable[Any], /, *iterables: Iterable[Any], strict: bool = ...) -> zip[tuple[Any, ...]]
prd/yardl_types.py:299: error: "object" has no attribute "value"  [attr-defined]
prd/_ndjson.py:48: error: Incompatible types in assignment (expression has type "TextIO", variable has type "TextIOWrapper")  [assignment]
prd/_ndjson.py:86: error: Incompatible types in assignment (expression has type "BufferedReader | TextIO", variable has type "TextIOWrapper")  [assignment]
prd/_ndjson.py:940: error: <nothing> has no attribute "to_json"  [attr-defined]
prd/_ndjson.py:958: error: <nothing> has no attribute "from_json"  [attr-defined]
prd/_ndjson.py:993: error: Incompatible types in assignment (expression has type "None", variable has type "tuple[int, ...]")  [assignment]
prd/_ndjson.py:1024: error: Need type annotation for "result"  [var-annotated]
prd/_binary.py:1071: error: Incompatible types in assignment (expression has type "None", variable has type "tuple[int, ...]")  [assignment]
prd/_binary.py:1076: error: <nothing> has no attribute "_element_serializer"  [attr-defined]
prd/_binary.py:1115: error: Need type annotation for "result"  [var-annotated]
johnstairs commented 8 months ago

@KrisThielemans, getting clean results with Mypy is proving to be difficult, as it often gets confused and emits many spurious errors. Pyright, on the other hand, doesn't seem to have as many of these issues and is much faster.

There are legitimate issues that we will clean up, and then we will enable strict Pyright checking in our CI. Making mypy happy would require a lot of suppressions.

I am inclined to recommend Pyright over Mypy when using Yardl. Do you have an opinion on this?

KrisThielemans commented 8 months ago

I am inclined to recommend Pyright over Mypy when using Yardl. Do you have an opinion on this?

Sure. You guys know much better than me.

johnstairs commented 7 months ago

Generated code should now run clean with Pyright (also in strict mode). Addressed in #102