Last active
September 23, 2022 20:31
-
-
Save viniciusao/9e6690ebfcf1fd93b3d59e891aa65b4c to your computer and use it in GitHub Desktop.
NamedTuple typing normal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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