Skip to content

Instantly share code, notes, and snippets.

@viniciusao
Last active September 23, 2022 20:31
Show Gist options
  • Save viniciusao/9e6690ebfcf1fd93b3d59e891aa65b4c to your computer and use it in GitHub Desktop.
Save viniciusao/9e6690ebfcf1fd93b3d59e891aa65b4c to your computer and use it in GitHub Desktop.
NamedTuple typing normal
from typing import NamedTuple
class FunctionNumber101(NamedTuple):
width: float
height: float
def area(self):
if self.width <= 0 or self.height <= 0:
raise ValueError("width and height must be positive")
return self.width * self.height
square = FunctionNumber101(10, 10)
assert square.area() == 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment