basedmypy
basedmypy copied to clipboard
Based Python static type checker with baseline, sane default settings and based typing features
```py from typing import Generic from basedtyping import T class A(Generic[T]): def __init__(self, t: T = 1): ... a = A() ```
need to add explicit base class `ABC`
To make an iterable that doesn't support `str`: ```py class WorkProperlyIterable(Iterable[out_T], Protocol): __contains__: NotRequired["(object) -> bool"] ```
```py from __future__ import annotations from typing import Callable, Never from basedtyping import P class A: pass def f(fn: Callable[P, object]): ... a: A & Callable[[Never], object] b: A &...
something like: ```py class _Wrapped(Protocol[_PWrapped, _RWrapped]): __wrapped__: Callable[_PWrapped, _RWrapped] C = TypeVar("C", bound=Callable) class _Wrapper(Generic[_PWrapped, _RWrapped]): def __call__(self, f: C) -> _Wrapped[_PWrapped, _RWrapped] & C: ... ``` well, `_Wrapper` is...
Turns out that it is needed in code, who woulda guessed... # Workaround ```py class Named(Protocol): __name__: str __qualname__: str a: "(int) -> str" & Named ```
in contextlib.pyi it should be: ```py class ContextDecorator: def __call__(self, func: "(P) -> R") -> "def (P) -> R": ... ```
simple scenario: ```py @overload def f(a: str) -> int: ... @overload def f(a: int) -> str: ... def f(a): return a ``` more realistic scenario: ```py from typing import overload...
```py from typing import TypeVar T = TypeVar("T") R = TypeVar("R", bound=T) def foo(t: T, r: R): ... o: object f: float foo(f, o) # no error ```