Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created Sep 19, 2021
Shared via mypy Playground
View main.py
from typing import Generic, TypeVar, Mapping
T = TypeVar("T")
T2 = TypeVar("T2")
class A(dict[T, T2]):
...
def foo(**i: float) -> None:
...
@mypy-play
mypy-play / main.py
Created Sep 19, 2021
Shared via mypy Playground
View main.py
from typing import Iterator, Generic, TypeVar
T = TypeVar("T")
T2 = TypeVar("T2")
class A(Iterator[T2], Generic[T, T2]):
...
a: A[str, Iterator[int]]
reveal_type((*a,))
reveal_type([*a])
b: list[int] = [*a]
@mypy-play
mypy-play / main.py
Created Sep 18, 2021
Shared via mypy Playground
View main.py
from typing import Iterator, Generic, TypeVar
T = TypeVar("T")
T2 = TypeVar("T2")
class A(Iterator[T2], Generic[T, T2]):
...
a: A[int, Iterator[int]]
reveal_type((*a,))
reveal_type([*a])
b: list[int] = [*a]
@mypy-play
mypy-play / main.py
Created Sep 18, 2021
Shared via mypy Playground
View main.py
from typing import Iterator, Generic, TypeVar
T = TypeVar("T")
T2 = TypeVar("T2")
class A(Iterator[T2], Generic[T, T2]):
...
a: A[int, list[int]]
i = [*a]
reveal_type(i)
@mypy-play
mypy-play / main.py
Created Sep 18, 2021
Shared via mypy Playground
View main.py
import html
@mypy-play
mypy-play / main.py
Created Sep 17, 2021
Shared via mypy Playground
View main.py
from __future__ import annotations
import sys
from collections.abc import Sequence
from os import PathLike
from pathlib import Path
from typing import Any, BinaryIO, TextIO, Union
FileDesignator = Union[PathLike[Any], str, bytes]
FileHandle = Union[TextIO, BinaryIO]
@mypy-play
mypy-play / main.py
Created Sep 17, 2021
Shared via mypy Playground
View main.py
from __future__ import annotations
from collections.abc import Sequence
from os import PathLike
from pathlib import Path
from typing import Any, BinaryIO, TextIO, Union
FileDesignator = Union[PathLike[Any], str, bytes]
FileHandle = Union[TextIO, BinaryIO]
input_files: Sequence[FileDesignator]
@mypy-play
mypy-play / main.py
Created Sep 17, 2021
Shared via mypy Playground
View main.py
from __future__ import annotations
from collections.abc import Sequence
from os import PathLike
from pathlib import Path
from typing import Any, BinaryIO, TextIO, Union
FileDesignator = Union[PathLike[Any], str, bytes]
FileHandle = Union[TextIO, BinaryIO]
input_files: Sequence[FileDesignator]
@mypy-play
mypy-play / main.py
Created Sep 17, 2021
Shared via mypy Playground
View main.py
from typing import Callable
d: dict[int, Callable[..., str]] = {}
d[0]: Callable[[int], str] = lambda i: str(i)
"""
Failed (exit code: 1) (2703 ms)
main.py:4: error: Unexpected type declaration
Found 1 error in 1 file (checked 1 source file)
@mypy-play
mypy-play / main.py
Created Sep 17, 2021
Shared via mypy Playground
View main.py
from typing import Callable
d: dict[int, Callable[..., str]] = {}
d[0]: Callable[[int], str] = lambda i: str(i)
"""
Failed (exit code: 1) (2946 ms)
main.py:4: error: Unexpected type declaration
Found 1 error in 1 file (checked 1 source file)