birds.py:16: error: “Bird” has no attribute “quack”
woody.py:5: error: Argument 1 to “alert_duck” has incompatible type “Bird”;
expected “Duck”
Found 2 errors in 2 files (checked 1 source file)
첫 번째 에러는
birds.py
에 있다.
alert_bird()
안에서의
birdie.quack()
호출은 이
미 앞에서 보았다. 두 번째 에러는
woody.py
에 있다.
woody
는
Bird
인스턴스이므로
alert_
duck(woody)
을 호출할 수 없다.
alert_duck()
함수가
Duck
인스턴스를 인자로 요구하기
때문이다. 모든
Duck
은
Bird
이지만, 모든
Bird
가
Duck
은 아니다.
실행 시
woody.py
안의 호출 중 성공하는 게 없다. [예제
8
-
7
]과 같이 콘솔 세션을 이용하면
연속해서 호출이 실패하는 모습을 잘 볼 수 있다.
예제
8-7
실행 에러 및
Mypy
로 에러를 예방할 수 있었던
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.