Skip to content

Instantly share code, notes, and snippets.

@mypy-play
mypy-play / main.py
Created May 2, 2024 13:44
Shared via mypy Playground
# mypy: allow-untyped-defs
from typing import Any
from robustmq.consumer import BlockingConsumer
class BlockingConsumerExtended(BlockingConsumer): # type: ignore[no-untyped-def]
def _declare_queue(self) -> None:
assert self.channel is not None
@mypy-play
mypy-play / main.py
Created May 2, 2024 08:04
Shared via mypy Playground
from typing import overload, SupportsInt, TypeVar
T = TypeVar('T')
@overload
def to_int(value: SupportsInt) -> int: ...
@overload
def to_int(value: T) -> T | int: ...
@mypy-play
mypy-play / main.py
Created May 2, 2024 07:31
Shared via mypy Playground
from typing import Any, SupportsInt, TypeVar, Union, overload
T = TypeVar('T')
@overload
def to_int(value: SupportsInt) -> int: ...
@overload
def to_int(value: T) -> T: ...
@mypy-play
mypy-play / main.py
Created May 2, 2024 03:57
Shared via mypy Playground
import sys
print(sys.version)
@mypy-play
mypy-play / main.py
Created May 2, 2024 01:03
Shared via mypy Playground
from typing import TypeVar, Protocol, Generic, Callable, Any
T = TypeVar("T")
# MyPy: error: Missing return statement [empty-body]
# MyPy: error: A function returning TypeVar should receive at least one argument containing the same TypeVar [type-var]
# PyRight: TypeVar "T" appears only once in generic function signature.
# Use "object" instead (reportInvalidTypeVarUse)
def f_expecting_Nothing_returning_T() -> T:...
# PyRight: TypeVar "T" appears only once in generic function signature.
@mypy-play
mypy-play / main.py
Created May 1, 2024 23:12
Shared via mypy Playground
from typing import (
Literal,
overload,
Sequence,
TypeVar,
Union,
)
T1 = TypeVar('T1')
T2 = TypeVar('T2')
@mypy-play
mypy-play / main.py
Created May 1, 2024 23:12
Shared via mypy Playground
from typing import (
Literal,
overload,
Sequence,
TypeVar,
Union,
)
T1 = TypeVar('T1')
T2 = TypeVar('T2')
@mypy-play
mypy-play / main.py
Created May 1, 2024 21:13
Shared via mypy Playground
from typing import Protocol, Generic, TypeVar, runtime_checkable, Any, get_args, ClassVar
from abc import ABC, abstractmethod
from collections.abc import Sequence
class DeploymentConfig:
...
class DeploymentProto(Protocol):
config: DeploymentConfig
@mypy-play
mypy-play / main.py
Created May 1, 2024 21:08
Shared via mypy Playground
from typing import Protocol, Generic, TypeVar, runtime_checkable, Any, get_args, ClassVar
from abc import ABC, abstractmethod
from collections.abc import Sequence
class DeploymentConfig:
...
class DeploymentProto(Protocol):
config: DeploymentConfig
@mypy-play
mypy-play / main.py
Created May 1, 2024 21:06
Shared via mypy Playground
def foo(myvar: str | None="test") -> str | None:
if myvar is None:
return None
reveal_type(myvar)
return myvar.upper()