Created
November 16, 2024 02:12
-
-
Save mypy-play/295b711fade0d8f27bd73ef50145a7e6 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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: | |
def __init__(self, project_id: str | None, dataset_id: str): | |
pass | |
@classmethod | |
def from_string(cls, dataset_id: str, default_project_id: str | None = None) -> DatasetReference: | |
return cls(default_project_id, dataset_id) | |
FOO = EnvVar("FOO") | |
BAR = EnvVar("BAR", int) | |
BAZ = EnvVar("BAZ", DatasetReference.from_string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment