Some types and operations are defined by default to match what Python provides (e.g. literal types and their operations). The checker also supports importing custom type definitions from Midas files.
Currently, type checking is strict: types must match exactly. This is especially true for function return types, which must all be the same in a given function, and ternary expressions, whose branches must be of the same type.
Subtyping and genericity will be added in a separate PR
The type checker generates a list of diagnostics (errors, warnings and infos), which can be highlighted in the source file using the following command:
uv run midas compile -l highlighted.html -t types.midas source.py
This PR implements a basic type checker. It handles simple python constructs such as:
- literals (i.e. booleans, integers, floats, strings)
- variable assignment (w/ and w/o type annotation)
- variable references
- binary operations (i.e. `+`, `-`, `*`, `/`, etc.)
- comparisons (i.e. `>`, `<`, `>=`, `<=`, etc.)
- logical operations (i.e. `and`, `or`)
- `if` statements
- ternary expression
- function definition
- function call
- return statements
- casting (i.e. `cast(Type, expression)`)
Some types and operations are defined by default to match what Python provides (e.g. literal types and their operations). The checker also supports importing custom type definitions from Midas files.
Currently, type checking is strict: types must match exactly. This is especially true for function return types, which must all be the same in a given function, and ternary expressions, whose branches must be of the same type.
Subtyping and genericity will be added in a separate PR
The type checker generates a list of diagnostics (errors, warnings and infos), which can be highlighted in the source file using the following command:
```shell
uv run midas compile -l highlighted.html -t types.midas source.py
```
this is still very basic and only handle a few expressions
notably, it doesn't support generics, option types, conditions, predicates nor complex types
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
This PR implements a basic type checker. It handles simple python constructs such as:
+,-,*,/, etc.)>,<,>=,<=, etc.)and,or)ifstatementscast(Type, expression))Some types and operations are defined by default to match what Python provides (e.g. literal types and their operations). The checker also supports importing custom type definitions from Midas files.
Currently, type checking is strict: types must match exactly. This is especially true for function return types, which must all be the same in a given function, and ternary expressions, whose branches must be of the same type.
Subtyping and genericity will be added in a separate PR
The type checker generates a list of diagnostics (errors, warnings and infos), which can be highlighted in the source file using the following command: