2017-03-28 5 views
0

다음 함수에서 docstring을 정의하는 방법은 무엇입니까?PyCharm + python2.7에서 일반 반환 유형을 지정하는 방법

from sample.utils import get_object 
from sample.models import User 

u = get_object(User, name='test') 
u. # no PyCharm hint here 

또한 또한 :(

작동하지 :type klass: T:rtype: T을 시도 : 나는 klass을 시도했습니다

def get_object(klass, **kwargs): 
    """ 
    :rtype: ??? 
    """ 
    # perform some tasks 
    return klass(**kwargs) 

, type(klass), klass.__class__, 모두 분리 모듈 파일에서 작동하지 않았다

PyCharm에서 이러한 종류의 구문을 문서화 문자열에서 지원할 수 있습니까? 문서화 방법

이 같은

답변

1

시도 뭔가 : 당신이 클래스의 인스턴스 유형으로 람다의 반환 형식을 사용할 수 있도록

def get_obj(klass, **kwargs): 
""" 
:type klass: ((object) -> T) | T 
:type kwargs: object 
:rtype: T 
""" 

클래스, 그 __init__의 람다 될 수

관련 문제