ch25: added checkeddeco example

This commit is contained in:
Luciano Ramalho
2021-04-22 19:39:49 -03:00
parent 177d914c9f
commit 8ec5fd0861
4 changed files with 241 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
from checkeddeco import checked
@checked
class Movie:
title: str
year: int
megabucks: float
if __name__ == '__main__':
movie = Movie(title='The Godfather', year=1972, megabucks=137)
print(movie.title)
print(movie)
try:
# remove the "type: ignore" comment to see Mypy error
movie.year = 'MCMLXXII' # type: ignore
except TypeError as e:
print(e)
try:
blockbuster = Movie(title='Avatar', year=2009, megabucks='billions')
except TypeError as e:
print(e)