Skip to content

Instantly share code, notes, and snippets.

@willmcgugan
Created October 18, 2021 08:31
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 willmcgugan/77397ac49ce7e37f2aa220db60915988 to your computer and use it in GitHub Desktop.
Save willmcgugan/77397ac49ce7e37f2aa220db60915988 to your computer and use it in GitHub Desktop.
from typing import NamedTuple, Tuple, Union
class ConsoleDimensions(NamedTuple):
width: int
height: int
class TestClass:
def __init__(self) -> None:
self._width = 3
self._height = 4
@property
def size(self) -> Union[ConsoleDimensions, Tuple[int, int]]:
return ConsoleDimensions(self._width, self._height)
@size.setter
def size(self, new_size: Tuple[int, int]) -> None:
width, height = new_size
self._width = width
self._height = height
a = TestClass()
a.size = (4, 5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment