I've been using python for a good few months.
And im really bothered by some aspects of the documentation.
I think that there should be a clear effort to provide API style information, rather than the mixed state that things currently are.
There are tools for C++/Java...that are part of the official distributions that provide API style docs.
Here's what gets me: when u look up something in pydoc, you have no idea what it returns/expects in terms of types. Now, since python is not an explicitely typed language, I ask rhetorically, how can u have good docs that tell u the return/input types without making the language explicitely typed?
Make the documenation system explictely typed.
The clarification needs to happen somewhere along the lines, and I really think that the world would rather not have it happening at runtime.
This could clear up a lot of confusion and further python's effectiveness.
-Hunter.
Hunter Peress hu.peress@mail.mcgill.ca writes:
This could clear up a lot of confusion and further python's effectiveness.
It's not clear, to me, from reading your message, what kind of change you are requesting (that you are requesting a change, rather than offering help, or asking for advice, appears to be clear).
Could you kindly provide a small patch that gives an idea of what you would like to see changed, and how?
TIA, Martin
From: "Hunter Peress" hu.peress@mail.mcgill.ca
def something(a,b,c="lalal"): """This will find its way into the pydocs because its a comment""" ##Here is the new stuff Im proposing ##note, a clearer sytnax can surely be devised. """file""" #documents the type of the first arg """string""" # "" second """list""" # "" third """string""" #documents the return type.
Then the pydoc generator will do a check on the # arguments to the func/meth, verify that the correct amount of these new comments (which only supply the type) are provided. I do think that it would help to actually enforce this. I think its fine that doc's NOT be generated if they don't supply this information. This provides for better docs and shouldnt get that many complaints.
Thanks for the clarification. I see what you're trying to do; however, I think that any gains are more than offset by the new level of complexity and lengthier code.
The current docs make a pretty good effort at describing what is needed for each argument. At the same time, they allow flexibility for dynamic arguments that share a similar interface (such as substituting a StringIO object for a File object.
In your example, the docs strings could be made clear using existing tools:
def something(file, promptstring, optionlist): """Returns a string extracted from the file for any line matching the promptstring. The optionlist can include any of the following: IGNORECASE, VERBOSE. MULTILINE, or ADDLINENUMBER."""
I can't see that a tool like you described would add any more clarity than the above docstring.
PS whats TIA mean?
"Thanks In Advance"
Do you have any examples of current python docstrings that are not clear enough?
Raymond Hettinger
While I understand what you're trying to do here (and think it would be quite nice), I'm not sure how you're going to accomplish it. How will parsing python using a syntax-tree help? It's not going to tell you what the function does in all cases or the various types it could handle. Perhaps you could make educated guesses by looking at the types of operations on the objects (a 'has_key' is a sure indicator of a hash), but that would be sketchy at best.
For a ready example, imagine having a module that contains useful helper functions. How are you going to identify the type requirements of those functions if you don't have context? How can you be sure that you've convered all contexts (including conversions).
Such is the nature of dynamic languages. It's very hard to do what you'd like to do here.
-- Mike
On Sat, Sep 07 @ 21:22, Hunter Peress wrote:
I think its easier to enforce this from the level i describe, than have guido saying "ok guys please be more explicit in your documentation". I mean, both of those documents above are somewhat explicit, but they are not COMPLETE.
Could you provide me with some linkage on parsing python (from a compilation/ syntax-tree analysis POV). SO that i can get to work on writing a patch for the pydoc generation program.
Ok. I think I understand better what you're trying to accomplish. I got the impression earlier (and I think others did as well) that you were hoping to have pydoc automatically label types on the function call. A new convention might very well be welcomed. You might want to post a couple of examples and the corresponding documentation for feedback here before you start the hard work on the patch :)
More below...
On Sun, Sep 08 @ 02:11, Hunter Peress wrote:
Actually all of the thinking i did WAS taking into account the "dynamic" nature of python.
But its not like the actual code is being rewritten fast enough to make this unfeasible or unneccesary.
Im glad to get all of this feedback as its helping me formulate, and further specify my plans (or eventually healthily debunk them (as the past 3 responders have helped do)).
Instead of just thinking:
"arguments are not explicitely anything, therefore it makes no sense to even attempt to document them explicitely".
I think this: simply add the capability for multiple definitions per each argument. eg going back to my original sample here is an updated version:
def something(a,b,c="lalal"): """This will find its way into the pydocs because its a comment""" ##Here is the new stuff Im proposing ##note, a clearer sytnax can surely be devised. """file,socket""" #documents the type(s) of the first arg """string,list""" # "" second """list,hash""" # "" third """string,hash""" #documents the return type(s).
Thats quite a simple solution, and still provides worlds better exactness and clarity than the current system allows.
Onto more of your concerns: On Wed, 2002-09-04 at 23:45, Michael Gilfix wrote:
While I understand what you're trying to do here (and think it would be quite nice), I'm not sure how you're going to accomplish it. How will parsing python using a syntax-tree help? It's not going to tell you what the function does in all cases or the various types it could handle.Perhaps you could make educated guesses by looking at the types of operations on the objects (a 'has_key' is a sure indicator of a hash), but that would be sketchy at best.
Actually I wasnt suggesting this AT ALL wrt intelligent guesses, and for now this proposal leans away from it.
Rather there are only 2 simple things that I wanted to obtain from the parse-tree: the number of arguments, and if possible to see if there
Agreed now that things are clearer.
Assume for now that my whole proposal will simply be another option (instead of the default) to the pydoc-generator program. If invoked, it will fail (if the super strict option is specified) if you don't supply definitions for number of args for a given method.
This brings up your "dynamic" language issue again.
When u have lots of args being used as different things, my program then introduces another level of complexity to deciphering the docs in a meaningful way.
Eg: a sample output of this program based on my example:
------------output----------------- method: something(a (file,socket),b (string,list),c="lalal" (list,hash)) return type :string,hash
This will find its way into the pydocs because its a comment
Now in html format it would be even nicer as there will be links to the types listed.
I agree. I know that I'd welcome an extra added option to enable some extra pydoc functionality. Developing a schema is tricky though and you should probably engage in some more debate first :)
And now looking at it, I think its much clearer than nothing at al.
Of course there is going to be that type of code where u have no need of documenting every method because their names are self explantory, and such explicit documentation isnt necessary, thats not what this is really intended for.
If the specific argument arises that "since python is a dynamic language your approach doesnt make sense" say, then I have to respond:
Of course it applies. Because of my misunderstanding, I was under the impression that you wanted to generate the equivalent of function calls, not develop a scheme like javadoc. The dynamic nature of Python means that such specifications become even more important as project sizes increase.
an attempt at specifiying things is FAR better than nothing, and moreover, this is only my first attempt. Allowing it to become a part of the generator as an option will open it up to user input, and hence improvement, AND!
it might just turn out that a "dynamic" approach will be necessary to document a "dynamic" language.
So im still looking for more design tips, and a place where I could find out how to get into the meat of the python parser, but i think the "http://python.org/doc/2.2/lib/module-parser.html" is probably what I'll be using.
Shouldn't there be code in the existing pydoc to do much of what you want for you? It seems like it might be nice to re-engineer pydoc to take some handlers that allow you to do further customization after it's done it's thing. That way, we can add extensions into the existing code and all that integration stuff might be a little easier.
Good luck n' keep us posted :)
-- Mike
hunter wrote:
I need not search far. example 1) pydoc os.fork Python Library Documentation: built-in function fork in os fork(...) fork() -> pid Fork a child process.
Return 0 to child process and PID of child to parent process.
why do you care about the type of a PID object? in most cases, all you need to know is that a PID isn't 0, which is exactly what the documentation says.
and if you know what a PID is, you already know what type it is...
example2) pydoc string.index Python Library Documentation: function index in string index(s, *args) index(s, sub [,start [,end]]) -> int
Like find but raises ValueError when the substring is not found.
From these two, I have no idea what BOTH the input and return types are.
the index documentation refers to the documentation for "find", which tells you that:
help(string.find)
Help on function find in module string:
find(s, *args) find(s, sub [,start [,end]]) -> in
Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation.
Return -1 on failure.
which, given that you know how indexes and slices work in python, is all you need to know.
I found those examples in 10 seconds (literally). The state of the python documentation is caca.
how long have you been using Python?
</F>
my only objection is that the case where fork fails isn't documented. with a C background one expects a negative number, when in fact an exception is raised...
Ah jeez. Even with only half a day of Python you should've figured out that Python nearly always raises an exception where the corresponding C code returns an error value.
--Guido van Rossum (home page: http://www.python.org/~guido/)
Hunter Peress wrote:
example 1) pydoc os.fork Python Library Documentation: built-in function fork in os fork(...) fork() -> pid Fork a child process.
Return 0 to child process and PID of child to parent process.
my only objection is that the case where fork fails isn't documented. with a c background one expects a negative number, when in fact an exception is raised...
erik
guido wrote:
my only objection is that the case where fork fails isn't documented. with a C background one expects a negative number, when in fact an exception is raised...
Ah jeez. Even with only half a day of Python you should've figured out that Python nearly always raises an exception where the corresponding C code returns an error value.
otoh, it doesn't hurt to spell it out for functions like fork which almost always succeeds...
(can you write a portable test that is guaranteed to raise an exception, and does that without locking up the system?)
</F>
fre 2002-09-06 klockan 16.41 skrev Guido van Rossum:
my only objection is that the case where fork fails isn't documented. with a C background one expects a negative number, when in fact an exception is raised...
Ah jeez. Even with only half a day of Python you should've figured out that Python nearly always raises an exception where the corresponding C code returns an error value.
It would, however, be extremely useful if the documentation spelled out *which* exceptions can be raised! Kind of hard to write a decent try/except clause if you don't know what to expect.
Regards, Martin
It would, however, be extremely useful if the documentation spelled out *which* exceptions can be raised! Kind of hard to write a decent try/except clause if you don't know what to expect.
Yes, *this* is a deficiency in the Python docs that ought to be fixed. It's a lot of work though, and it's not always clear what to document (e.g. *everything* can raise MemoryError -- so it's not useful to mention that everywhere).
--Guido van Rossum (home page: http://www.python.org/~guido/)
Ok heres some more detail.
I have no idea how pydoc works right now. I assume you call some program on a python file, and it simply looks for all """ """.
It seems to do SOME lexical/scoping analysis of where to look for """ """, and consequently, how to display that information in the final,doc form; but I'm asking for more.
As I said, python methods/functions are not explcitely typed. So what I propose is this:
When the pydoc generator comes accross a function/method, there should remain a normal """ """ area for any comments. I'm asking now, that when the generator sees its in a method/function, it does a NEW check for a set of docs that document the type of each input argument, and the output.
EG (theoretical, and off the top of my head):
in a file you have a function:
def something(a,b,c="lalal"): """This will find its way into the pydocs because its a comment""" ##Here is the new stuff Im proposing ##note, a clearer sytnax can surely be devised. """file""" #documents the type of the first arg """string""" # "" second """list""" # "" third """string""" #documents the return type.
Then the pydoc generator will do a check on the # arguments to the func/meth, verify that the correct amount of these new comments (which only supply the type) are provided. I do think that it would help to actually enforce this. I think its fine that doc's NOT be generated if they don't supply this information. This provides for better docs and shouldnt get that many complaints.
Then: If the docs are generated into webpages, links to the known types that are checked are provided. And if the docs are going into shell format then i dont know if links are necessary.
There are lots of cases and issues that I havent discussed for this proposed implemenation. So I would like to continue this thread for the purposes of detailing this idea further.
This could clear up a lot of confusion and further python's effectiveness.
As we know, python is not an explicitely typed language, but enforcing some level of typing at the documentation level will see a lot of people falling into line (depending on how rigidly its enforced, and i do suggest a pretty rigid level).
I have no patch ATM because I tend to design software before writing it, and im looking for support from the developers first.
PS whats TIA mean?
On Wed, 2002-09-04 at 17:56, Martin v. Loewis wrote:
Hunter Peress hu.peress@mail.mcgill.ca writes:
This could clear up a lot of confusion and further python's effectiveness.
It's not clear, to me, from reading your message, what kind of change you are requesting (that you are requesting a change, rather than offering help, or asking for advice, appears to be clear).
Could you kindly provide a small patch that gives an idea of what you would like to see changed, and how?
TIA, Martin
On Wed, 2002-09-04 at 19:19, Raymond Hettinger wrote:
From: "Hunter Peress" hu.peress@mail.mcgill.ca
def something(a,b,c="lalal"): """This will find its way into the pydocs because its a comment""" ##Here is the new stuff Im proposing ##note, a clearer sytnax can surely be devised. """file""" #documents the type of the first arg """string""" # "" second """list""" # "" third """string""" #documents the return type.
Then the pydoc generator will do a check on the # arguments to the func/meth, verify that the correct amount of these new comments (which only supply the type) are provided. I do think that it would help to actually enforce this. I think its fine that doc's NOT be generated if they don't supply this information. This provides for better docs and shouldnt get that many complaints.
Thanks for the clarification. I see what you're trying to do; however, I think that any gains are more than offset by the new level of complexity and lengthier code.
The current docs make a pretty good effort at describing what is needed for each argument. At the same time, they allow flexibility for dynamic arguments that share a similar interface (such as substituting a StringIO object for a File object.
In your example, the docs strings could be made clear using existing tools:
def something(file, promptstring, optionlist): """Returns a string extracted from the file for any line matching the promptstring. The optionlist can include any of the following: IGNORECASE, VERBOSE. MULTILINE, or ADDLINENUMBER."""
I can't see that a tool like you described would add any more clarity than the above docstring.
PS whats TIA mean?
"Thanks In Advance"
Do you have any examples of current python docstrings that are not clear enough?
this was the impetus behind my whole thinking here.
I need not search far. example 1) pydoc os.fork Python Library Documentation: built-in function fork in os fork(...) fork() -> pid Fork a child process.
Return 0 to child process and PID of child to parent process.
example2) pydoc string.index Python Library Documentation: function index in string index(s, *args) index(s, sub [,start [,end]]) -> int
Like find but raises ValueError when the substring is not found.
Actually all of the thinking i did WAS taking into account the "dynamic" nature of python.
But its not like the actual code is being rewritten fast enough to make this unfeasible or unneccesary.
Im glad to get all of this feedback as its helping me formulate, and further specify my plans (or eventually healthily debunk them (as the past 3 responders have helped do)).
Instead of just thinking:
"arguments are not explicitely anything, therefore it makes no sense to even attempt to document them explicitely".
I think this: simply add the capability for multiple definitions per each argument. eg going back to my original sample here is an updated version:
def something(a,b,c="lalal"): """This will find its way into the pydocs because its a comment""" ##Here is the new stuff Im proposing ##note, a clearer sytnax can surely be devised. """file,socket""" #documents the type(s) of the first arg """string,list""" # "" second """list,hash""" # "" third """string,hash""" #documents the return type(s).
Thats quite a simple solution, and still provides worlds better exactness and clarity than the current system allows.
Onto more of your concerns: On Wed, 2002-09-04 at 23:45, Michael Gilfix wrote:
While I understand what you're trying to do here (and think it would be quite nice), I'm not sure how you're going to accomplish it. How will parsing python using a syntax-tree help? It's not going to tell you what the function does in all cases or the various types it could handle.Perhaps you could make educated guesses by looking at the types of operations on the objects (a 'has_key' is a sure indicator of a hash), but that would be sketchy at best.
Actually I wasnt suggesting this AT ALL wrt intelligent guesses, and for now this proposal leans away from it.
Rather there are only 2 simple things that I wanted to obtain from the parse-tree: the number of arguments, and if possible to see if there
Assume for now that my whole proposal will simply be another option (instead of the default) to the pydoc-generator program. If invoked, it will fail (if the super strict option is specified) if you don't supply definitions for number of args for a given method.
This brings up your "dynamic" language issue again.
When u have lots of args being used as different things, my program then introduces another level of complexity to deciphering the docs in a meaningful way.
Eg: a sample output of this program based on my example:
------------output----------------- method: something(a (file,socket),b (string,list),c="lalal" (list,hash)) return type :string,hash
This will find its way into the pydocs because its a comment -----------------------------------
Now in html format it would be even nicer as there will be links to the types listed.
And now looking at it, I think its much clearer than nothing at al.
Of course there is going to be that type of code where u have no need of documenting every method because their names are self explantory, and such explicit documentation isnt necessary, thats not what this is really intended for.
If the specific argument arises that "since python is a dynamic language your approach doesnt make sense" say, then I have to respond:
an attempt at specifiying things is FAR better than nothing, and moreover, this is only my first attempt. Allowing it to become a part of the generator as an option will open it up to user input, and hence improvement, AND!
*** it might just turn out that a "dynamic" approach will be necessary to document a "dynamic" language. ***
So im still looking for more design tips, and a place where I could find out how to get into the meat of the python parser, but i think the "http://python.org/doc/2.2/lib/module-parser.html" is probably what I'll be using.
For a ready example, imagine having a module that contains useful helper functions. How are you going to identify the type requirements of those functions if you don't have context? How can you be sure that you've convered all contexts (including conversions).
Such is the nature of dynamic languages. It's very hard to do what you'd like to do here.
-- Mike
On Sat, Sep 07 @ 21:22, Hunter Peress wrote:
I think its easier to enforce this from the level i describe, than have guido saying "ok guys please be more explicit in your documentation". I mean, both of those documents above are somewhat explicit, but they are not COMPLETE.
Could you provide me with some linkage on parsing python (from a compilation/ syntax-tree analysis POV). SO that i can get to work on writing a patch for the pydoc generation program.
-- Michael Gilfix mgilfix@eecs.tufts.edu
For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html"
for i in a: print os.spawnv(os.P_NOWAIT,scr,["",str(i)])
for i in a: os.wait()
you have to do the second loop in order to wait for all children that u spawned off. I think that os.wait() without any arguments should wait for all chilren, not wait for the earliest executed child.
On Thu, 2002-09-05 at 17:06, Fredrik Lundh wrote:
hunter wrote:
I need not search far. example 1) pydoc os.fork Python Library Documentation: built-in function fork in os fork(...) fork() -> pid Fork a child process.
Return 0 to child process and PID of child to parent process.
why do you care about the type of a PID object? in most cases, all you need to know is that a PID isn't 0, which is exactly what the documentation says.
and if you know what a PID is, you already know what type it is...
example2) pydoc string.index Python Library Documentation: function index in string index(s, *args) index(s, sub [,start [,end]]) -> int
Like find but raises ValueError when the substring is not found.
From these two, I have no idea what BOTH the input and return types are.
the index documentation refers to the documentation for "find", which tells you that:
help(string.find)
Help on function find in module string:
find(s, *args) find(s, sub [,start [,end]]) -> in
Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.
which, given that you know how indexes and slices work in python, is all you need to know.
I found those examples in 10 seconds (literally). The state of the python documentation is caca.
how long have you been using Python?
</F>
for i in a: print os.spawnv(os.P_NOWAIT,scr,["",str(i)])
for i in a: os.wait()
you have to do the second loop in order to wait for all children that u spawned off. I think that os.wait() without any arguments should wait for all chilren, not wait for the earliest executed child.
Go talk to the designers of Unix and the POSIX standard committee.
--Guido van Rossum (home page: http://www.python.org/~guido/)
The idea came from bash. where the wait command will wait for all child processes.
Its clearly doable. On Mon, 2002-09-23 at 10:42, Guido van Rossum wrote:
for i in a: print os.spawnv(os.P_NOWAIT,scr,["",str(i)])
for i in a: os.wait()
you have to do the second loop in order to wait for all children that u spawned off. I think that os.wait() without any arguments should wait for all chilren, not wait for the earliest executed child.
Go talk to the designers of Unix and the POSIX standard committee.
--Guido van Rossum (home page: http://www.python.org/~guido/)
Hunter Peress hu.peress@mail.mcgill.ca:
I think that os.wait() without any arguments should wait for all chilren, not wait for the earliest executed child.
Actually, it waits for *any* one child to exit, not necessarily the first one spawned.
In any case, the functions in the os module are supposed to be direct wrappers of the platform's system calls.
Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+