Commit 21fdd0a
committed
Add classes_and_objects_exercise2.py: demonstrate mypy type checking
- Create Person class with type-annotated __init__ method
- Add name (str), age (int), and preferred_operating_system (str) attributes
- Implement is_adult() function that correctly accesses Person.age attribute
- Add is_adult_wrong_attribute() function that intentionally accesses non-existent Person.address
- Demonstrate mypy error detection for invalid attribute access
- Show how mypy validates correct vs incorrect property references1 parent 6f0982b commit 21fdd0a
1 file changed
Lines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
0 commit comments