ch25: new example with __init_subclas__

This commit is contained in:
Luciano Ramalho
2021-04-17 21:02:51 -03:00
parent 4ff0a59608
commit 177d914c9f
3 changed files with 201 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
from checkedlib import Checked
class Movie(Checked):
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)