This file contains 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 Type | |
from typing import Any | |
from typing import TypeVar | |
from typing import cast | |
T = TypeVar("T") | |
def assert_type(x: Any, type: Type[T]) -> None: | |
if not isinstance(x, type): | |
raise TypeError() |
This file contains 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 __future__ import annotations | |
x: int | float |
This file contains 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
x: int | float |
This file contains 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 Generic, Any, overload | |
from typing_extensions import TypeVar | |
class C: | |
pass | |
class CustomC(C): | |
pass | |
_C = TypeVar('_C', bound=C, default=C) |
This file contains 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 collections.abc import Callable | |
def pprint(obj: object, repr_fn: Callable[..., str] = NotImplemented) -> str: | |
repr_fn = ( | |
repr_fn # expression has type "function", variable has type "Callable[..., str]" | |
if repr_fn is not NotImplemented | |
else repr | |
) | |
return repr_fn(obj) |
This file contains 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 collections.abc import Callable | |
def pprint(obj: object, repr_fn: Callable[..., str] = NotImplemented): | |
repr_fn = ( | |
repr_fn # expression has type "function", variable has type "Callable[..., str]" | |
if repr_fn is not NotImplemented | |
else repr | |
) | |
return repr_fn(obj) |
This file contains 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 collections.abc import Callable | |
def pprint(obj: object, repr_fn: Callable[..., str] = NotImplemented): | |
repr_fn = ( | |
repr_fn if repr_fn is not NotImplemented | |
else repr | |
) | |
return repr_fn(obj) |
This file contains 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 typing as t | |
class C: | |
pass | |
_C = t.TypeVar('_C', bound=C) | |
class A(t.Generic[_C]): | |
def __init__(self, c: type[_C] | None = None) -> None: | |
self._c = c or C |
This file contains 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 typing as t | |
class C: | |
pass | |
_C = t.TypeVar('_C', bound=C) | |
class A(t.Generic[_C]): | |
def __init__(self, c: type[_C] | None = None) -> None: | |
self._c = c or C |
This file contains 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 ParamSpec, TypeVar, Callable, Literal, NewType | |
from dataclasses import dataclass | |
S3EventType = Literal["S3"] | |
SQSEventType = Literal["SQS"] | |
SQSRecord = NewType("SQSRecord", str) | |
AWSEventTypes = S3EventType | SQSEventType |
NewerOlder