简体   繁体   English

PyCharm 类型提示:未检测到返回类型

[英]PyCharm type hinting: return type not detected

I want to add type hinting to PyCharm, but PyCharm does not detect the return type if I use cached_property instead of property .我想向 PyCharm 添加类型提示,但如果我使用cached_property而不是property ,PyCharm 不会检测返回类型。

class MyClass(object):

    #@cached_property # does not work
    @property         # works
    def foo_client(self):
        '''
        @rtype foo.Client
        '''
        return client_getter(...)

Usage:用法:

my_class = MyClass()
my_class.foo_client.HERE_I_WANT_AUTOCOMPLETE

I use cached-property==1.1.0 and PyCharm 4.5.我使用cached-property==1.1.0和 PyCharm 4.5。

Since you're using an EAP build, this problem can have several solutions.由于您使用的是 EAP 版本,此问题可以有多种解决方案。

  1. Revert back to the old PyCharm.恢复到旧的 PyCharm。 EAP builds are buggy and often have problems with older features. EAP 构建有问题,并且经常在旧功能上出现问题。 This might actually be the case since PyCharm is trying to add support for type hinting (Python 3.5) and so you might have a problem with the code completion that you're getting.这实际上可能是这种情况,因为 PyCharm 正在尝试添加对类型提示(Python 3.5)的支持,因此您可能会遇到代码完成问题。

  2. The format in which you're writing your stubs is called Epytype, and is almost never used anywhere, so it can often fail to work.您编写存根的格式称为 Epytype,并且几乎从未在任何地方使用过,因此它经常无法工作。 I would suggest using reStructuredText instead.我建议改用 reStructuredText。 Just change the document format from "Eypdoc/Epytype" to reStructuredText inside of Python Integrated Tools > Docstrings.只需在 Python Integrated Tools > Docstrings 中将文档格式从“Eypdoc/Epytype”更改为 reStructuredText。 This will most likely solve the problem.这很可能会解决问题。

  3. If points 1 and 2 fail.如果第 1 点和第 2 点失败。 Then this is a genuine bug and I suggest that you report it at youtrack.jetbrains.那么这是一个真正的错误,我建议您在 youtrack.jetbrains 上报告它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM