Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created May 1, 2025 17:01
Shared via mypy Playground
from typing import Optional, Union, cast, Literal, NewType, TypeGuard
from collections import defaultdict
from dataclasses import dataclass
@dataclass
class Application:
id: int
parent_id: Optional[int] = None
ParentApplication = NewType('ParentApplication', Application)
@mypy-play
mypy-play / main.py
Created May 1, 2025 17:01
Shared via mypy Playground
from typing import Optional, Union, cast, Literal, NewType, TypeGuard
from collections import defaultdict
from dataclasses import dataclass
@dataclass
class Application:
id: int
parent_id: Optional[int] = None
ParentApplication = NewType('ParentApplication', Application)
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:55
Shared via mypy Playground
from typing import Optional, Union, cast, Literal, NewType, TypeGuard
from collections import defaultdict
from dataclasses import dataclass
@dataclass
class Application:
id: int
parent_id: Optional[int] = None
ParentApplication = NewType('ParentApplication', Application)
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:49
Shared via mypy Playground
from typing import Optional, Union, cast, Literal, NewType, TypeGuard
from collections import defaultdict
from dataclasses import dataclass
@dataclass
class Application:
id: int
parent_id: Optional[int] = None
ParentApplication = NewType('ParentApplication', Application)
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:48
Shared via mypy Playground
from typing import Optional, Union, cast, Literal, NewType, TypeGuard
from collections import defaultdict
from dataclasses import dataclass
@dataclass
class Application:
id: int
parent_id: Optional[int] = None
ParentApplication = NewType('ParentApplication', Application)
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:45
Shared via mypy Playground
from collections.abc import AsyncIterator, Callable
from typing import Any, Callable
type TaskGroup = Any
create_task_group: Any
async def yield_to_start[*A, R](
tg: TaskGroup,
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:07
Shared via mypy Playground
"""
Functions for *walking* the DOM.
!!! note
For most purposes you would be better off using [query][textual.dom.DOMNode.query], which uses these functions internally.
"""
from __future__ import annotations
@mypy-play
mypy-play / main.py
Created May 1, 2025 16:01
Shared via mypy Playground
from typing import Any
var: tuple[int, ...]
fix: tuple[int, int] = var
var2: tuple[Any, ...]
fix2: tuple[Any, Any] = var2
@mypy-play
mypy-play / main.py
Created May 1, 2025 14:36
Shared via mypy Playground
StrList = list[str]
StrListPair = tuple[StrList, StrList]
T = list[StrListPair]
result: T = [
(['a', 'b', 'c'], ['d', 'e', 'f', 'g']),
(['a', 'b', 'c'], ['d', 'e', 'f', 'g']),
(['a', 'b', 'c'], ['d', 'e', 'f', 'g']),
]
@mypy-play
mypy-play / main.py
Created May 1, 2025 14:26
Shared via mypy Playground
from typing import *
class B():
def f(self) -> Self:
return self
class C(B):
pass
class D(B):
pass