This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import reveal_type | |
def non_optional[T](value: T|None)->T: | |
assert value is not None | |
return value | |
def f(x: int|None): | |
reveal_type(x) | |
y = non_optional(x) | |
reveal_type(y) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options: list[tuple[int, *tuple[str, ...]]] = [(1, 'a'), (2, 'b', 'c')] | |
for i, *s in options: | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i, s in [(1, ('a',)), (2, ('b', 'c'))]: | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
options: list[tuple[int, *tuple[str, ...]]] = [(1, 'a'), (2, 'b', 'c')] | |
for i, *s in options: | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for i, *s in [(1, 'a'), (2, 'b', 'c')]: | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, cast | |
i: int | |
s: tuple[str] | |
for i, *s in cast(tuple[Any, ...], [(1, 'a'), (2, 'b', 'c')]): | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, cast | |
i: int | |
s: tuple[str] | |
for i, *s in cast(tuple[Any, ...], [(1, 'a'), (2, 'b', 'c')]): | |
print(hex(i), '_'.join(s)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from typing import Awaitable, AsyncGenerator | |
async def foo(*coros: Awaitable[None]) -> bool: | |
gen = (False for f in coros if not await f) | |
# Revealed type is "typing.Generator[builtins.bool, None, None]" | |
# Runtime type is 'async_generator' | |
reveal_type(gen) | |
return await anext(gen) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, cast | |
# A skeleton class based on Django's BaseForm: | |
# https://github.com/typeddjango/django-stubs/blob/master/django-stubs/forms/forms.pyi | |
class BaseForm: | |
cleaned_data: dict[str, Any] = {} | |
def clean(self) -> dict[str, Any] | None: | |
return self.cleaned_data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Any, cast | |
class BaseForm: | |
cleaned_data: dict[str, Any] = {} | |
def clean(self) -> dict[str, Any] | None: | |
return self.cleaned_data | |
NewerOlder