3 ms·
In some cases don't you need to actually execute the code to know what the type actually is. How does the type checker know then?
by tayo42 2y ago
In some cases don't you need to actually execute the code to know what the type actually is. How does the type checker know then?
- maleldil 2y agoIt doesn't. There are cases where the type-checker can't know the type (e.g. json.load has to return Any), but there are tools in the language to reduce how much that happens. If you commit to a fully strictly-typed codebase, it doesn't happen often.
- sevensor 2y agoYou can actually annotate the return type of json.load better than that: JSON = float | bool | int | str | None | list[“JSON”] | dict[str, “JSON”]