Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created November 10, 2025 22:46
Show Gist options
  • Save mypy-play/e9e82ec0c3d4edd6379a7dac403359be to your computer and use it in GitHub Desktop.
Save mypy-play/e9e82ec0c3d4edd6379a7dac403359be to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from __future__ import annotations
from typing import TypeVar
T = TypeVar("T", bound=str | int)
VALUES: dict[str, str] = {"SIZE": "100", "ADDR": "0x100", "NAME": "potato"}
def get_parameter(parameter: str, _rtype: type[T]) -> T:
"""Get the parameter"""
if parameter.startswith("N"):
return int(VALUES[parameter], 0)
return VALUES[parameter]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment