如何在 PyCharm + python2.7 中指定泛型 return 类型
How to specifying generic return type in PyCharm + python2.7
如何在以下函数中定义文档字符串?
def get_object(klass, **kwargs):
"""
:rtype: ???
"""
# perform some tasks
return klass(**kwargs)
我试过了klass
、type(klass)
、klass.__class__
、
它们都不能在单独的模块文件中工作:
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
,也没有用 :(
PyCharm 可以在 docstring 中支持这些语法吗?
如何记录?
尝试这样的事情:
def get_obj(klass, **kwargs):
"""
:type klass: ((object) -> T) | T
:type kwargs: object
:rtype: T
"""
Class可以是其__init__
的lambda,所以可以使用lambda的return类型作为class
的实例类型
如何在以下函数中定义文档字符串?
def get_object(klass, **kwargs):
"""
:rtype: ???
"""
# perform some tasks
return klass(**kwargs)
我试过了klass
、type(klass)
、klass.__class__
、
它们都不能在单独的模块文件中工作:
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
,也没有用 :(
PyCharm 可以在 docstring 中支持这些语法吗? 如何记录?
尝试这样的事情:
def get_obj(klass, **kwargs):
"""
:type klass: ((object) -> T) | T
:type kwargs: object
:rtype: T
"""
Class可以是其__init__
的lambda,所以可以使用lambda的return类型作为class