简体   繁体   中英

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 .

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.

Since you're using an EAP build, this problem can have several solutions.

  1. Revert back to the old PyCharm. EAP builds are buggy and often have problems with older features. 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.

  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. I would suggest using reStructuredText instead. Just change the document format from "Eypdoc/Epytype" to reStructuredText inside of Python Integrated Tools > Docstrings. This will most likely solve the problem.

  3. If points 1 and 2 fail. Then this is a genuine bug and I suggest that you report it at youtrack.jetbrains.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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