Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created May 18, 2024 22:37
Shared via mypy Playground
from typing import overload, Literal
class Base:
pass
class A(Base):
pass
class B(Base):
@mypy-play
mypy-play / main.py
Created May 18, 2024 19:23
Shared via mypy Playground
class A:
pass
class B(A):
def say_hello(self):
pass
def func_of_a(var1: A) -> None:
@mypy-play
mypy-play / main.py
Created May 18, 2024 06:31
Shared via mypy Playground
class A:
pass
class B(A):
def say_hello(self):
pass
def func_of_a(var1: A) -> None:
@mypy-play
mypy-play / main.py
Created May 18, 2024 06:31
Shared via mypy Playground
class A:
pass
class B(A):
def say_hello(self):
pass
def func_of_a(var1: A) -> None:
@mypy-play
mypy-play / main.py
Created May 18, 2024 06:30
Shared via mypy Playground
class A:
pass
class B(A):
def say_hello(self):
pass
def func_of_a(var1: A) -> None:
@mypy-play
mypy-play / main.py
Created May 18, 2024 04:46
Shared via mypy Playground
from typing import Protocol, Iterator, TypeVar
T = TypeVar('T', covariant = True)
class Grouping(Protocol[T]):
@staticmethod
def __class_getitem__(key):
...
def __iter__(self) -> Iterator[T]:
...
@mypy-play
mypy-play / main.py
Created May 18, 2024 02:28
Shared via mypy Playground
from typing import Literal
a: int = 3
if isinstance(a, float):
reveal_type(a) # Never touched at runtime, but Mypy says `int`.
b: Literal[3] = 3
if isinstance(b, float):
@mypy-play
mypy-play / main.py
Created May 17, 2024 22:34
Shared via mypy Playground
import typing as t
a: t.Literal[1 | None]
reveal_type(a)
@mypy-play
mypy-play / main.py
Created May 17, 2024 22:22
Shared via mypy Playground
import typing as t
a: t.Literal[1 | 2]
reveal_type(a)
@mypy-play
mypy-play / main.py
Created May 17, 2024 16:37
Shared via mypy Playground
from typing import TypedDict, TYPE_CHECKING, Any
class Movie(TypedDict):
name: str
year: int
def isassignable(x: object, T: type) -> bool:
return True