Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created November 16, 2024 02:12
Show Gist options
  • Save mypy-play/295b711fade0d8f27bd73ef50145a7e6 to your computer and use it in GitHub Desktop.
Save mypy-play/295b711fade0d8f27bd73ef50145a7e6 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
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