Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created November 16, 2024 02:10
Show Gist options
  • Save mypy-play/b4021ddb8eba737e35b96fa00fe70bb8 to your computer and use it in GitHub Desktop.
Save mypy-play/b4021ddb8eba737e35b96fa00fe70bb8 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", dataset_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment