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 dataclasses import dataclass, fields | |
import os | |
@dataclass(kw_only=False) | |
class ConveyorInfo: | |
conveyor_id: str | |
conveyor_run_id: int | |
release_identifier: str | |
revert: bool |
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 Callable | |
type ValueConverter[T] = Callable[[str], T] | |
class EnvVar[T]: | |
def __init__(self, key: str, convert: ValueConverter[T] = str): | |
self.key = key | |
self.convert = convert | |
class DatasetReference: |
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 Callable | |
type ValueConverter[T] = Callable[[str], T] | |
class EnvVar[T]: | |
def __init__(self, key: str, convert: ValueConverter[T] = str): | |
self.key = key | |
self.convert = convert | |
class DatasetReference: |
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 foo(x: str, y: str = '') -> str: | |
return 'foo' | |
bar: Callable[[str], str] = foo |
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 enum | |
from typing import Literal, Protocol, TypeVar | |
class ISOCode(enum.StrEnum): | |
CAISO = "CAISO" | |
ERCOT = "ERCOT" | |
MISO = "MISO" |
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 enum import Enum | |
class E(Enum): | |
A = 1 | |
B = 2 | |
C = 3 | |
def ret_num(self) -> str: | |
match self: | |
case E.A: |
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 Final, Literal | |
def fun(x: Literal["a", "b"]) -> None: | |
print(x) | |
def use_fun() -> None: | |
var = "a" | |
fun(var) # mypy doesn't seem clever enough to infer that var is "a" |
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 Final, Literal | |
class Rgb: | |
RED: Final = "red" | |
GREEN: Final = "green" | |
BLUE: Final = "blue" | |
BLACK: Final = "black" |
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 Iterator | |
def fib(n: int) -> Iterator[int]: | |
a, b = 0, 1 | |
while a < n: | |
yield a | |
a, b = b, a + b |
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 Final | |
from dataclasses import dataclass | |
@dataclass | |
class A: | |
a: Final = 1 | |
b: Final[int] = 1 | |
NewerOlder