전자는 올 경우, arg
수용 의 인스턴스를CustomClass
:
def FuncA(arg: CustomClass):
# ^ instance of CustomClass
클래스 CustomClass
자체 (또는 하위 유형) 를 원하는 경우 다음과 같이 작성해야합니다.
from typing import Type # you have to import Type
def FuncA(arg: Type[CustomClass]):
# ^ CustomClass (class object) itself
타이핑 에 대한 문서에 쓰여진 것처럼 :
class typing.Type(Generic[CT_co])
주석이 달린 변수 C
는 유형 값을 허용 할 수 있습니다 C
. 반대로, 가변 주석이 Type[C]
자신있는 클래스 값을 허용 할 수있다 - 즉, 그것은 허용 할 클래스 개체C
.
설명서에는 int
클래스 와 함께 예제가 포함되어 있습니다 .
a = 3 # Has type 'int'
b = int # Has type 'Type[int]'
c = type(a) # Also has type 'Type[int]'
Type
py3.6 이후부터? 나는 단지NameError
.