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 pathlib import Path | |
import os | |
base = os.path.join("gitsb", "repo") | |
target = "sdr" | |
params = { | |
"target": str(), | |
"destination": str(), |
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 logging | |
import functools | |
def add_logging(f): | |
@functools.wraps(f) | |
def inner(*args, **kwargs): | |
logging.info(f"call | {f.__name__}: {args} , {kwargs}") | |
result = f(*args, **kwargs) | |
logging.info(f"finish | {f.__name__} returned {result}") | |
return result |
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 | |
class NDArray: | |
shape: tuple | |
def __setitem__(self, idx: NDArray, v: object) -> None: ... | |
def random(x: object) -> NDArray: return NDArray() | |
Image = typing.NewType('Image', NDArray) | |
Mask = typing.NewType('Mask', NDArray) |
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 | |
import numpy as np | |
Image = typing.NewType('Image', np.ndarray) | |
Mask = typing.NewType('Mask', np.ndarray) | |
image_array = np.random.random((50, 50)) | |
image = Image(array) | |
mask_array = np.random.random((50, 50)) |
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 | |
class NDArray: | |
shape: tuple | |
def __setitem__(self, idx: NDArray, v: object) -> None: ... | |
def random(x: object) -> NDArray: return NDArray() | |
Image = typing.NewType('Image', NDArray) | |
Mask = typing.NewType('Mask', NDArray) |
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 Literal | |
class Meta(type): | |
def __bool__(self) -> Literal[True]: | |
return True | |
class Foo(metaclass=Meta): | |
pass | |
class Bar: |
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 overload, Literal | |
@overload | |
def x(a: int = 5, t: Literal[True] = True, b: int = 5) -> int: ... | |
@overload | |
def x(a: int = 5, *, t: Literal[False], b: int = 5) -> str: ... | |
@overload | |
def x(a: int, t: Literal[False], b: int = 5) -> str: ... |
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 TypedDict, Unpack | |
def my_func_1(arg1: int, arg2: bool, arg3: str): | |
pass | |
class MyFuncArgs(TypedDict): | |
arg1: int | |
arg2: bool | |
arg3: str | |
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 | |
def foo(x: list[list[int]]) -> list[int] | None: | |
reveal_type(min(x, key=len, default=None)) # N: Revealed type is "Union[builtins.list[builtins.int], None]" | |
return min(x, key=len, default=None) # E: Argument "key" to "min" has incompatible type "Callable[[Sized], int]"; expected "Callable[[list[int] | None], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type] | |
foos: list[list[int]] | |
reveal_type(min(foos, key=len, default=None)) # N: Revealed type is "Union[builtins.list[builtins.int], None]" | |
min_foo: list[int] | None = min(foos, key=len, default=None) # E: Argument "key" to "min" has incompatible type "Callable[[Sized], int]"; expected "Callable[[list[int] | None], SupportsDunderLT[Any] | SupportsDunderGT[Any]]" [arg-type] |
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
rom abc import ABC, abstractmethod | |
from typing import Union | |
class Task(ABC): | |
@abstractmethod | |
def run(self) -> None: | |
return | |