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

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

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
735
17
반복자, 제너레이터, 고전적인 코루틴
이제 이번 장을 마치기 전에 코루틴의 자료형 힌트에서 공변성과 반변성이라는 이해하기 어려
운 주제를 살펴보자.
17
.
13
.
3
고전적 코루틴에 대한 제네릭형 힌트
15
.
7
.
4
절의 ‘반변성’에서
typing.Generator
를 반변성 자료형 인수가 있는 몇 안 되는 표준 라
이브러리 함수라고 설명했다. 지금까지 고전적 코루틴에 관해 알아보았으니 이제 제네릭형을
이해할 준비가 되었다.
파이썬
3
.
6
typing.py
모듈에는
typing.Generator
(
https://fpy.li/17-25
)가 다음과
같이 선언되었다.
17
T_co = TypeVar(‘T_co’, covariant=True)
V_co = TypeVar(‘V_co’, covariant=True)
T_contra = TypeVar(‘T_contra’, contravariant=True)
# 중략
class Generator(Iterator[T_co], Generic[T_co, T_contra, V_co],
extra=_G_base):
이 제네릭형 선언은
Generator
형 힌트 선언에 앞에서 본 자료형 인수 세 개가 필요함을 의미
한다.
my_coro : Generator[YieldType, SendType, ReturnType]
형식 인수의 자료형 변수 중 ...
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