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 TypeVar | |
U = TypeVar('U', bound=int) | |
class X[U]: | |
u: U | |
def do(self, var: U) -> None: | |
pass | |
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 typing | |
def apply_on_answer[T](f: typing.Callable[[int], T], /) -> T: | |
return f(42) | |
class C: | |
@apply_on_answer | |
def x(answer: int) -> int: | |
return answer | |
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
# distutils/extension.py | |
from dataclasses import dataclass, field, fields | |
import os | |
import warnings | |
from typing import TYPE_CHECKING, Iterable | |
@dataclass | |
class _Extension: | |
name: str |
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
# distutils/extension.py | |
from __future__ import annotations | |
import os | |
from collections.abc import Iterable | |
from typing import TYPE_CHECKING, TypedDict, Union | |
if TYPE_CHECKING: | |
from typing_extensions import TypeAlias, Unpack | |
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 warnings import deprecated | |
@deprecated("f is deprecated") | |
def f(): ... | |
f() | |
@deprecated("Will be removed in Python 3.14") | |
def g(): ... |
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 word(name: str) -> str: | |
return f"my name is {name}" | |
print(word("evan")) |
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 requests | |
endpoint = "https://gitlab.uk/merge_requests" | |
headers = {"PRIVATE_TOKEN": "SECRET"} | |
branch = "banana" | |
params = {"state": "opened", "scope": "all", "target_branch": branch, "author_id": 87, "view": "simple"} | |
response = requests.get(endpoint, headers=headers, params=params) |
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 typing as tp | |
class Wrapped[**P, T]: | |
def __call__(self, *args: P.args, **kwargs: P.kwargs) -> T: | |
raise NotImplementedError | |
def inner[**P, T](f: tp.Callable[P, T]) -> Wrapped[P, T]: | |
assert False |
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 typing import overload | |
class A[T]: ... | |
class B[T: (int, str)](A[T]): | |
@overload | |
def __new__(cls: type[B[int]]) -> B[int]: ... | |
@overload | |
def __new__(cls: type[B[str]]) -> B[str]: ... | |
def __new__(cls): raise NotImplementedError |
NewerOlder