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

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

by 루시아누 하말류, 강권학
November 2024
Beginner to intermediate
1064 pages
25h 21m
Korean
Hanbit Media, Inc.
Content preview from 전문가를 위한 파이썬(2판)
1014
5
메타프로그래밍
이제
Checked
클래스를 살펴보자. 소스 코드를 두 부분으로 나누었다. [예제
24
-
5
]는 클래스
의 앞부분을 보여 주는데, 이 예제에서 가장 중요한 메서드들이 포함된다. 나머지 메서드는 [예
24
-
6
]에 있다.
예제
24-5
i
nitsub
/
checkedlib
.
py
:
Checked
클래스의 가장 중요한 메서드들
class Checked:
@classmethod
def _fields(cls) -> dict[str, type]: ❶
return get_type_hints(cls)
def __init_subclass__(subclass) -> None: ❷
super().__init_subclass__() ❸
for name, constructor in subclass._fields().items(): ❹
setattr(subclass, name, Field(name, constructor)) ❺
def __init__(self, **kwargs: Any) -> None:
for name in self._fields(): ❻
value = kwargs.pop(name, ...) ❼
setattr(self, name, value) ❽
if kwargs: ❾
self.__flag_unknown_attrs(*kwargs) ❿
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