Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instance variables set using __pdoc__ don't work #107

Open
JPLeBreton opened this issue May 27, 2016 · 6 comments

Comments

Projects
None yet
3 participants
@JPLeBreton
Copy link

commented May 27, 2016

If I have something like:

class Foo:
    a,b,c = 0, 1, 2
    def __init__(self):
        self.d, self.e, self.f = 3, 4, 5

Class variables a,b,c show up in the generated docs, but instance variables d,e,f do not.
Expected result: instance variables declared in this manner should show up in generated docs.

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented May 27, 2016

Instance variables are detected by parsing the AST. I'd prefer a lower tech solution. You must write each instance variable on its own line, or modify __pdoc__ directly.

@JPLeBreton

This comment has been minimized.

Copy link
Author

commented Jun 1, 2016

Okay, thanks. I'm trying to work out how to do the latter; nothing I try is working. From the example above, would I do this?

__pdoc__ = {}
__pdoc__['Foo.d'] = "Docstring for Foo's d instance variable."
class Foo:
    a,b,c = 0, 1, 2
    def __init__(self):
        self.d, self.e, self.f = 3, 4, 5

or __pdoc__['mymodule.Foo.d']? or something else?

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented Jun 1, 2016

From the docs:

Thirdly and finally, docstrings can be overrided with a special pdoc dictionary that pdoc inspects if it exists. The keys of pdoc should be identifiers within the scope of the module. (In the case of an instance variable self.variable for class A, its module identifier would be A.variable.) The values of pdoc should be docstrings.

So Foo.d should work.

It looks like your example doesn't work, which means this is probably a bug. It looks like putting each instance variable on its own line does work though.

@JPLeBreton

This comment has been minimized.

Copy link
Author

commented Jun 1, 2016

Thanks. Shall I file a bug for that related-but-separate issue?

@BurntSushi BurntSushi changed the title Instance variables on multiple-assignment lines don't get exported Instance variables set using __pdoc__ don't work Jun 2, 2016

@BurntSushi

This comment has been minimized.

Copy link
Contributor

commented Jun 2, 2016

This issue is fine. I renamed the title. I don't think I'll ever support multiple instance variables defined on the same line.

@DewaldDeJager

This comment has been minimized.

Copy link

commented Apr 30, 2017

+1 for adding support for multiple instance variables defined on the same line. Wanted to see if there wasn't an issue on this already before opening one. My use case:

(self.var1, self.var2, self.var3) = self.method_that_returns_tuple()

Hopefully in future I can get some time and submit a pull request with this added. Thanks for the great tool, Andrew!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.