Skip to Content
전문가를 위한 파이썬(2판)
book

전문가를 위한 파이썬(2판)

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
326
2
객체로서의 함수
alert_duck(woody)
alert_bird(woody)
woody.py
를 검사할 때
Mypy
는 에러 두 가지를 찾아낸다.
…/birds/ $ mypy woody.py
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.
Start your free trial

You might also like

전문가를 위한 리액트

전문가를 위한 리액트

테자스 쿠마르
고성능 파이썬(2판)

고성능 파이썬(2판)

오현석, 미샤 고렐릭, 이안 오스발트

Publisher Resources

ISBN: 9791169211772