NREL / routee-compass

An energy-aware routing engine
https://nrel.github.io/routee-compass/
BSD 3-Clause "New" or "Revised" License
10 stars 5 forks source link

Finish adding mypy type checking #214

Open nreinicke opened 4 months ago

nreinicke commented 4 months ago

We've started adding type hints to the python wrapper of the app but haven't gotten full coverage. Add in any missing types and then we can activate the mypy check in our GitHub action.

SnoopJ commented 4 months ago

I'll take this one. I don't get any errors from mypy after installing the type stubs for what's needed, but if I add --strict I see a bunch of errors:

click for mypy errors ``` $ python3 -m mypy --strict python/ python/nrel/routee/compass/plot/plot_utils.py:2: error: Function is missing a type annotation [no-untyped-def] python/nrel/routee/compass/plot/plot_utils.py:7: error: Function is missing a type annotation [no-untyped-def] python/nrel/routee/compass/plot/plot_utils.py:10: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/plot/plot_utils.py:15: error: Call to untyped function "rgba_to_hex" in typed context [no-untyped-call] python/nrel/routee/compass/plot/plot_utils.py:20: error: Function is missing a type annotation [no-untyped-def] python/nrel/routee/compass/compass_app.py:33: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/compass_app.py:69: error: Missing type parameters for generic type "Dict" [type-arg] python/nrel/routee/compass/compass_app.py:87: error: Call to untyped function "get_constructor" of "CompassApp" in typed context [no-untyped-call] python/nrel/routee/compass/compass_app.py:91: error: Missing type parameters for generic type "Dict" [type-arg] python/nrel/routee/compass/compass_app.py:135: error: Returning Any from function declared to return "list[dict[str, Any]]" [no-any-return] python/nrel/routee/compass/compass_app.py:148: error: Returning Any from function declared to return "int" [no-any-return] python/nrel/routee/compass/compass_app.py:160: error: Returning Any from function declared to return "int" [no-any-return] python/nrel/routee/compass/compass_app.py:175: error: Returning Any from function declared to return "float" [no-any-return] python/nrel/routee/compass/compass_app.py:187: error: Returning Any from function declared to return "list[int]" [no-any-return] python/nrel/routee/compass/compass_app.py:199: error: Returning Any from function declared to return "list[int]" [no-any-return] python/nrel/routee/compass/io/generate_dataset.py:14: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/io/generate_dataset.py:14: error: Function is missing a type annotation for one or more arguments [no-untyped-def] python/nrel/routee/compass/io/generate_dataset.py:17: error: Missing type parameters for generic type "Dict" [type-arg] python/nrel/routee/compass/io/generate_dataset.py:19: error: Missing type parameters for generic type "Callable" [type-arg] python/nrel/routee/compass/io/generate_dataset.py:98: error: Function is missing a type annotation [no-untyped-def] python/tests/test_downtown_denver_example.py:8: error: Function is missing a return type annotation [no-untyped-def] python/tests/test_downtown_denver_example.py:8: note: Use "-> None" if function does not return a value python/tests/test_downtown_denver_example.py:27: error: Non-overlapping container check (element type: "str", container item type: "dict[str, Any]") [comparison-overlap] python/nrel/routee/compass/io/utils.py:66: error: Function is missing a type annotation for one or more arguments [no-untyped-def] python/nrel/routee/compass/io/utils.py:75: error: Function is missing a type annotation for one or more arguments [no-untyped-def] python/nrel/routee/compass/io/utils.py:107: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/io/utils.py:107: error: Function is missing a type annotation for one or more arguments [no-untyped-def] python/nrel/routee/compass/plot/plot_folium.py:16: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/plot/plot_folium.py:16: error: Function is missing a type annotation for one or more arguments [no-untyped-def] python/nrel/routee/compass/plot/plot_folium.py:17: error: Missing type parameters for generic type "dict" [type-arg] python/nrel/routee/compass/plot/plot_folium.py:18: error: Missing type parameters for generic type "dict" [type-arg] python/nrel/routee/compass/plot/plot_folium.py:122: error: Function is missing a return type annotation [no-untyped-def] python/nrel/routee/compass/plot/plot_folium.py:123: error: Missing type parameters for generic type "dict" [type-arg] python/nrel/routee/compass/plot/plot_folium.py:124: error: Missing type parameters for generic type "dict" [type-arg] python/nrel/routee/compass/plot/plot_folium.py:168: error: Call to untyped function "rgba_to_hex" in typed context [no-untyped-call] python/nrel/routee/compass/plot/plot_folium.py:170: error: Call to untyped function "ColormapCircularIterator" in typed context [no-untyped-call] Found 35 errors in 6 files (checked 11 source files) ```

After discussing with Nick, probably the check should be updated to add --strict since the goal of this is complete typing of the API. (I'm not sure if --install-types will make sense for the check or if that dependency on the type stubs should be declared explicitly somewhere)