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 collections.abc import Callable | |
import typing_extensions as t | |
P = t.ParamSpec("P") | |
T_co = t.TypeVar("T_co", covariant=True) | |
class ExpectCallable(t.Generic[P, T_co]): ... | |
class ExpectType(ExpectCallable[P, T_co]): ... |
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 Protocol | |
class Descriptor: | |
def __get__(self, instance, owner) -> int: | |
return 42 | |
class Foo(Protocol): | |
x: Descriptor = Descriptor() | |
class Bar(Protocol): |
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 Generic, TypeVar, cast, reveal_type | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) |
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 Generic, TypeVar, cast, reveal_type | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) |
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 Generic, TypeVar | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) |
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 Generic, TypeVar | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) |
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 Generic, TypeVar | |
T = TypeVar("T") | |
class Foo(Generic[T]): | |
def __init__(self, t: T): | |
self.t = t | |
def print(self, t: T): | |
print(t, self.t) |
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
def foo(*args: str) -> tuple[str, ...]: | |
return args | |
print(foo(args="a")) |
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 Iterator | |
def fib(n: int) -> Iterator[int]: | |
a, b = 0, 1 | |
while a < n: | |
yield a | |
a, b = b, a + b |
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 __future__ import annotations | |
from enum import IntEnum | |
from typing import Protocol, Self, cast, reveal_type | |
class SupportsAdd(Protocol): | |
def __add__(self, other: Self, /) -> Self: ... | |
def add_one[T: SupportsAdd](value: T) -> T: | |
match value: |
NewerOlder