Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created April 26, 2024 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mypy-play/8e3c55b817cd679d4e8c02a6eb30c4bd to your computer and use it in GitHub Desktop.
Save mypy-play/8e3c55b817cd679d4e8c02a6eb30c4bd to your computer and use it in GitHub Desktop.
Shared via mypy Playground
from typing import Dict, Iterator, TypeVar, Union
class A:
name: str = ""
K = TypeVar('K', bound=Union[str, A])
def a(arg: Dict[K, int]) -> None:
d = dict(
(k.name if isinstance(k, A) else k, v)
for k, v in arg.items()
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment