Helping analyzer detect return type

I'm noticing Pycharm doesn't detect my return types in some cases. Is there a coding convention that helps it do a better job, or a specially formatted comment? For example, if I have a factory type function, I'd like to report that the function returns something derived from a common base class.

class Base(object): pass
class Fancy(Base): pass
class Plain(Base): pass

def Factory(wantFancy):
    if wantFancy:
        return Fancy()
    else:
        return Plain()
    # NoteToPycharm: returns Base
1 comment

Hello Peter,

In PyCharm 1.5 EAP, you can use the @rtype (Epydoc) or :rtype (Sphinx) tag

in the docstring to specify the return type of the method. Another option

is to use the Python 3 annotations, which are also supported by PyCharm,

I'm noticing Pycharm doesn't detect my return types in some cases. Is

there a coding convention that helps it do a better job, or a

specially formatted comment? For example, if I have a factory type

function, I'd like to report that the function returns something

derived from a common base class.

class Base(object): pass

class Fancy(Base): pass

class Plain(Base): pass

def Factory(wantFancy):

if wantFancy:

return Fancy()

else:

return Plain()

  1. NoteToPycharm: returns Base

--

Dmitry Jemerov

Development Lead

JetBrains, Inc.

http://www.jetbrains.com/

"Develop with Pleasure!"

0

Please sign in to leave a comment.