basedmypy
basedmypy copied to clipboard
Based Python static type checker with baseline, sane default settings and based typing features
Pydantic et al evaluate types, and would be incompatable with a lot of based types, so: ```toml [tool.mypy] evaluated_type_bases = ["pydantic.BaseModel"] evaluated_type_decorators = ["pydantic.dataclasses.dataclass"] ```
```py a: object assert isinstance(a, list) reveal_type(a) # Revealed type is "list[Any]" (narrowed from "object") ``` Ideally, this should be `list[out object]` because it's invariant. but `object` at least would...
```py if TYPE_CHECKING: import x as y ``` # Workaround Add them to `__all__`
https://github.com/KotlinIsland/basedmypy/pull/630#issuecomment-1907241241
```py from typing import TYPE_CHECKING if TYPE_CHECKING is False: asdf # reachable if TYPE_CHECKING == False: asdf # reachable if not TYPE_CHECKING: asdf # unreachable ```
```py def foo(a: int) -> str: ... @func_type[foo] def bar(): # missing parameter 'a' return 1 # expected return str, found int # OR def bar(*args: ParamSpec[foo].args, **kwargs: ParamSpec[foo].kwargs) ->...
```py class A: def __init__(self): self.f = 1 print(A.f) # no error ``` HUUUHH?????
```py def foo() -> int: return exit(1) ``` This code is nonsense, yet there is no error.
make `float` not act like `float | int` (and `complex` act like `complex | float`) , and `bytes` not act like `bytes | memoryview | bytearray` we can still infer...
Reified Generics in basedtyping need special casing in basedmypy. `isinstance` and `issubclass`: ```py class Foo(ReifiedGeneric[T]): ... isinstance(Foo[int](), Foo[int]) ``` Ban `TypeVar`s: ```py def foo(t: T): a: ReifiedList[T] # should be...