documenting an alternate constructor?
I have code a little like this:
class Base(object): @classmethod def alternateConstructor(clazz, x): self = clazz() return self class Things(Base): def frob(self, y): pass def main(x): thing = Things.alternateConstructor(x)
and I'd like pycharm to be able to infer that "thing" an instance of "Things", but it doesn't seem to know that. Is there any way I can annotate the alternateConstructor to help it out?
请先登录再写评论。
Hello Kevin,
You can use epydoc or sphinx to specify the return rype of the alternateConstructor
function (or any other function, not only a constructor-like one).
--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"
Well, it appears as if it already understands that alternateConstructor returns a Base object. But I'm not going to document Base.alternateConstructor with ":rtype: Things" because that's not accurate. It would probably work to override Base.alternateConstructor as Things.alternateConstructor, but that would be otherwise redundant and serve no purpose to the code itself.