473,382 Members | 1,247 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

pydoc and imported modules

When I "from foo import *" in my __init__.py, sometimes module foo's
docs will be expanded in the pydocs. It seems to depend in what
language foo was implemented.

For example, if you "from math import *" in your __init__.py, you will
see math's members will appear in the resulting pydocs, as though it's
part of your module. The behavior is consistent across the C modules I
am writing.

However, if you "from foo import *" in your __init__.py, and foo is a
python file (not a module written in C), foo's members don't appear in
the resulting pydocs. This also seems to occur in some boost::python
bindings.

What is expected behavior? How do ensure foo's docs do or don't appear
in help, regardless of their implementation language?

Thanks,
Schpok

Apr 20 '07 #1
3 2244
sc****@gmail.com wrote:
When I "from foo import *" in my __init__.py, sometimes module foo's
docs will be expanded in the pydocs. It seems to depend in what
language foo was implemented.

For example, if you "from math import *" in your __init__.py, you will
see math's members will appear in the resulting pydocs, as though it's
part of your module. The behavior is consistent across the C modules I
am writing.

However, if you "from foo import *" in your __init__.py, and foo is a
python file (not a module written in C), foo's members don't appear in
the resulting pydocs. This also seems to occur in some boost::python
bindings.

What is expected behavior? How do ensure foo's docs do or don't appear
in help, regardless of their implementation language?

Thanks,
Schpok
Pydoc doesn't check the __module__ attribute of the items imported, it just
displays what is in the modules name space as if it was defined in that module.

In __init__.py files where an __all__ variable is defined, it won't show
items that aren't in __all__. This is probably what you are seeing.

I'm currently rewriting pydoc, so what behavior would you like to see?

Cheers,
Ron

Apr 25 '07 #2
I see. To make sure all my modules imported * are included in the
pydocs, I'll add:
__all__ = dir()
to the end of my __init__.py file.

Sometimes I implement a module with submodules, and flatten them out
in __init__.py so the user sees it all as one single module. For
example, module 'foobar' may be implemented in _foo and _bar, though I
want their contents exposed in the single module 'foobar'. So my
__init__.py would look like:

from _foo import *
from _bar import *

I noticed their pydocs weren't getting expanded if they were a)
implemented in python, or b) bound using boost::python (regular c
bindings and pyrex work). Apparently these approaches don't add their
members to __all__. It's odd to me that you can still call _foo's
member 'baz' through the foobar namespace, as though it is a member of
foobar.

I'm not sure if this is something that needs to be changed in pydoc.
If __all__ represents the public interface of a module, that should be
the thing we document. I was confused that __all__ behavior varied
with implementation, and understand that my python and boost::python
implementations may not be exporting their interface.

Thanks for illuminating the problem,

Schpok

On 4/25/07, Ron Adam <rr*@ronadam.comwrote:
sc****@gmail.com wrote:
When I "from foo import *" in my __init__.py, sometimes module foo's
docs will be expanded in the pydocs. It seems to depend in what
language foo was implemented.

For example, if you "from math import *" in your __init__.py, you will
see math's members will appear in the resulting pydocs, as though it's
part of your module. The behavior is consistent across the C modules I
am writing.

However, if you "from foo import *" in your __init__.py, and foo is a
python file (not a module written in C), foo's members don't appear in
the resulting pydocs. This also seems to occur in some boost::python
bindings.

What is expected behavior? How do ensure foo's docs do or don't appear
in help, regardless of their implementation language?

Thanks,
Schpok

Pydoc doesn't check the __module__ attribute of the items imported, it just
displays what is in the modules name space as if it was defined in that module.

In __init__.py files where an __all__ variable is defined, it won't show
items that aren't in __all__. This is probably what you are seeing.

I'm currently rewriting pydoc, so what behavior would you like to see?

Cheers,
Ron

Apr 25 '07 #3
sc****@gmail.com wrote:
When I "from foo import *" in my __init__.py, sometimes module foo's
docs will be expanded in the pydocs. It seems to depend in what
language foo was implemented.

For example, if you "from math import *" in your __init__.py, you will
see math's members will appear in the resulting pydocs, as though it's
part of your module. The behavior is consistent across the C modules I
am writing.

However, if you "from foo import *" in your __init__.py, and foo is a
python file (not a module written in C), foo's members don't appear in
the resulting pydocs. This also seems to occur in some boost::python
bindings.

What is expected behavior? How do ensure foo's docs do or don't appear
in help, regardless of their implementation language?

Thanks,
Schpok
Pydoc doesn't check the __module__ attribute of the items imported, it just
displays what is in the modules name space as if it was defined in that module.

In __init__.py files where an __all__ variable is defined, it won't show
items that aren't in __all__. This is probably what you are seeing.

I'm currently rewriting pydoc, so what behavior would you like to see?

Cheers,
Ron

Apr 25 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Colin J. Williams | last post by:
I am building a module which is based on the numarray package and its sub-packages. I am proposing to use PyDoc to document this module. The problem is that PyDoc generates links to...
0
by: Tony C | last post by:
According to the help for pydoc, it can be run as a script, from the command line. "Or, at the shell command line outside of Python: Run "pydoc <name>" to show documentation on something" ...
7
by: Brian van den Broek | last post by:
Hi all, I'm posting partly so my problem and solution might be more easily found by google, and partly out of mere curiosity. I've just spent a frustrating bit of time figuring out why pydoc...
9
by: newsposter | last post by:
>>> import pydoc >>> import sys >>> sys.version '2.4.2 (#67, Sep 28 2005, 12:41:11) ' >>> pydoc sys SyntaxError: invalid syntax >>> The documentation for pydoc says: "Run "pydoc <name>" to...
3
by: Rob Cowie | last post by:
I have searched this group and the wider net to find an answer to this, but I haven't been successful. Pydoc seems to be capable of writing documentation for all modules within a package by...
0
by: durumdara | last post by:
Hi ! I need to write documentation for my mod_python website, for the base classes, functions, modules. The problem, that mod_python is imported "apache" that not existing in the normal,...
4
by: Ron Adam | last post by:
This is for a new version of pydoc if I can get the class attributes sorted out. The module level attributes aren't too difficult to categorize. (I might be just too tired to see the obvious.) ...
0
by: w.m.gardella.sambeth | last post by:
Hello Pythonists: I am using SPE as python IDE on Windows, with Python 2.5.1 installed (official distro). As my mother tongue is Spanish, I had documented some modules in it (I now, I should have...
3
by: Mohamed Yousef | last post by:
Hello , The problem I'm asking about is how can imported modules be aware of other imported modules so they don't have to re-import them (avoiding importing problems and Consicing code and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.