basedmypy
basedmypy copied to clipboard
Based Python static type checker with baseline, sane default settings and based typing features
```py a = [] # E: error: Need type annotation for "a" (hint: "a: list[] = ...") [var-annotated] reveal_type(a) # E: Expression type contains "Any" (has type "list[Any (unannotated)]") [no-any-expr]...
```py class A[LowerBound[T, int]]: ... A[object] # ok A[int] # ok A[bool] # nah ``` # mypy in real life ```py class list[T]: def copy[R: lower=T](self) -> list[R]: ... a:...
```py a = [1, 2, 3] b: list[object] = a.copy() # error: invariance, expected no error ``` ```py class list[T]: def copy[R >: T]() -> list[R]: ... ``` (which doesn't...
```py a: Callable[[object], TypeGuard[int] ``` how denote? ```py a: Callable[[object], "argument 1 is int"] ```
it would be nice to have a variable like `TYPE_CHECKING` that's only true in basedmypy, so we can conditionally support based features while still supporting regular type checkers: ```py from...
The current solution is heuristic based and highly unsound. This will require reworking `AbstractContextManager` to know about the types of Exception and return type of `__exit__` ```py class Base: def...
```py print("hi") ``` ```console > mypy --run test.py Success: no issues found in 1 source file hi ```
```py a: object def guard() -> a is int: ... assert guard() reveal_type(a) ```
```py class A: value: int | str def f() -> bool: if self.guard(): return self.value.isnumeric() return False def guard(self) -> self.value is str: ... ```