Skip to content

Instantly share code, notes, and snippets.

@mypy-play
Created May 11, 2024 07:52
Show Gist options
  • Save mypy-play/624821e5afb466e1953ab2ab51fbdf13 to your computer and use it in GitHub Desktop.
Save mypy-play/624821e5afb466e1953ab2ab51fbdf13 to your computer and use it in GitHub Desktop.
Shared via mypy Playground
import typing as t
class C:
pass
_C = t.TypeVar('_C', bound=C)
class A(t.Generic[_C]):
def __init__(self, c: type[_C] | None = None) -> None:
self._c = c or C
@property
def c(self) -> type[_C]:
return self._c
@c.setter
def c(self, c: type[_C]) -> None:
self._c = c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment