ECMWFCode4Earth / vAirify

code repository for 2024 Code for Earth project #16
0 stars 0 forks source link

Investigate and fix the typing of variables #140

Open rstrange-scottlogic opened 1 week ago

rstrange-scottlogic commented 1 week ago

We are using Typed Dictionaries to allow some level of type checking in Python. There is currently a bug in pyCharm that does not do this type checking if there are more than 10 keys in the type : https://youtrack.jetbrains.com/issue/PY-51759/TypedDict-Keys-not-checked-by-static-checker-if-more-than-10-keys-long

So if you create a Forecast object for example and supply 11 keys, even if they are total nonsense, we get no type checking.

This will give you an error a: Forecast = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10}

This will not: a: Forecast = {"a": 1, "b": 2, "c": 3, "d": 4, "e": 5, "f": 6, "g": 7, "h": 8, "i": 9, "j": 10, "k": 11}

The workaround seems to be to use the dict constructor instead when creating typed dictionaries. This gives an error: a: Forecast = dict(a=1, b=2, c=3, d=4, e=5, f=6, g=7, h=8, i=9, j=10, k=11)

As another example all of our locations look like this I think: "location": { "type": "Point", "coordinates": {"0": 54.36667, "1": 24.46667}, }

But that doesn't appear to be a valid GeoJSONPoint that we're trying to type to

We need to go through the codebase and ensure our types are working correctly, and fix any cases where it doesn't.