bugGNU Octave - Bugs: bug #65258, Feature Request: provide function...

 
 

bug #65258: Feature Request: provide function prototype as docstring when no documentation exists

Submitter:  Rik <rik5>
Submitted:  Mon 05 Feb 2024 10:43:58 PM UTC
   
 
Category:  Documentation Severity:  1 - Wish
Priority:  3 - Low Item Group:  Feature Request
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  10.1.0 (current default) Planned Release:  10.1.0 (current default)
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Mon 25 Mar 2024 08:43:35 PM UTC, comment #17: 

Thanks for this.  It is a small thing, but I think it improves user experience quite a bit.

Marking bug as Fixed and closing report.

Rik <rik5>
Group administrator
Thu 21 Mar 2024 03:37:01 PM UTC, comment #16: 

I fixed 'help foo.foo' to return the default constructor signature when there is no constructor explicitly defined and also updated the tests in two additional changesets:

https://hg.savannah.gnu.org/hgweb/octave/rev/92ca2f6c6b85
https://hg.savannah.gnu.org/hgweb/octave/rev/c5dc54712378

The logic in these "help_system::raw_help*" functions seems a bit messy now, so maybe they could be better organized but at least they work now (I think).

This report can probably be closed now unless someone notices a problem with the latest changes.

John W. Eaton <jwe>
Group administrator
Thu 21 Mar 2024 06:12:12 AM UTC, comment #15: 

Looks good. 👍

The test in `test/bug-65220/bug-65220.tst` probably needs to be adapted for this change.

Markus Mützel <mmuetzel>
Group administrator
Thu 21 Mar 2024 03:18:29 AM UTC, comment #14: 

I pushed the following changeset.  Marking as ready for test.

https://hg.savannah.gnu.org/hgweb/octave/rev/515c1cc1b45e

John W. Eaton <jwe>
Group administrator
Wed 20 Mar 2024 09:02:19 PM UTC, comment #13: 

Uh, colon, not semi.

John W. Eaton <jwe>
Group administrator
Wed 20 Mar 2024 09:01:48 PM UTC, comment #12: 

The missing semicolon was a mistake.  I'll fix it.

John W. Eaton <jwe>
Group administrator
Wed 20 Mar 2024 08:58:51 PM UTC, comment #11: 

FWIW, I prefer a ':' to break things between the class of the message and the actual message itself.  Both warning and error messages start out with the class, for example "error: ", followed by the message.

Rik <rik5>
Group administrator
Wed 20 Mar 2024 08:53:07 PM UTC, comment #10: 

for consistency, should probably pick : or no : for the different formats.

Nicholas Jankowski <nrjank>
Group Member
Wed 20 Mar 2024 08:52:05 PM UTC, comment #9: 

new behaviors:

cli defined function:

octave:10> function y = no_doc_fcn (arg1, arg2, arg3)
end
octave:11> help no_doc_fcn
'no_doc_fcn' is a command-line function

undocumented function y = no_doc_fcn (arg1, arg2, arg3)

...


file defined function:

octave:15> help no_doc_fcn
'no_doc_fcn' is a function from the file /home/nrjank/source/builds/no_doc_fcn.m

undocumented function y = no_doc_fcn (arg1, arg2, arg3)

...


'empty' classdef file from comment #6:

octave:16> help no_doc_class
'no_doc_class' is a class constructor from the file /home/nrjank/source/builds/no_doc_class.m

default constructor: obj = no_doc_class()

...


classdef file with constructor from comment #7


octave:17> help foo_class
'foo_class' is a class constructor from the file /home/nrjank/source/builds/foo_class.m

undocumented constructor obj = foo_class (a, b, c = 2, ~)

...


Nicholas Jankowski <nrjank>
Group Member
Wed 20 Mar 2024 06:54:44 PM UTC, comment #8: 

I'm attaching a new version of the patch.  I thought it would be better to provide a method in the octave_user_function class to generate the function signature without any "undocumented function: " prefix.  The logic for deciding what to say about that signature is in the functions that search for the doc strings.

If this change looks OK, I can add a commit message and push to default.


(file #55871)

John W. Eaton <jwe>
Group administrator
Wed 20 Mar 2024 05:07:14 PM UTC, comment #7: 

If there is a constructor defined in a class but no doc for either the class or constructor:


classdef foo_class
  methods
    function obj = foo_class (a, b, c = 2, ~)
    end
  end
end


then I see


octave:1> help foo_class
'foo_class' is a class constructor from the file /scratch/jwe/build/octave/foo_class.m

undocumented function:  obj = foo_class (a, b, c = 2, ~)

[...]


I have an idea about how to improve the output so that we would say "undocumented constructor: ..." and to also display "default constructor:  obj = foo_class ()" if no constructor is explicitly defined.  I'll try to do that and upload another patch soon.

John W. Eaton <jwe>
Group administrator
Wed 20 Mar 2024 04:40:51 PM UTC, comment #6: 

testing against default, I now get the following with the comment #0 checks:

defined at the CLI:

function y = no_doc_fcn (arg1, arg2, arg3)
end



>> help no_doc_fcn
'no_doc_fcn' is a command-line function

undocumented function:  y = no_doc_fcn (arg1, arg2, arg3)

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.



same function saved to a file:

>> help no_doc_fcn
'no_doc_fcn' is a function from the file /home/nrjank/source/builds/no_doc_fcn.m

undocumented function:  y = no_doc_fcn (arg1, arg2, arg3)

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.


I see there's also a change to undoc'd classes.  if i create a dummy class file no_doc_class.m:


classdef no_doc_class
  properties
  endproperties

  methods
  endmethods
endclassdef


I get:

>> help no_doc_class
'no_doc_class' is a class constructor from the file /home/nrjank/source/builds/no_doc_class.m

no_doc_class is an undocumented class

Additional help for built-in functions and operators is
available in the online version of the manual.  Use the command
'doc <topic>' to search the manual index.

Help and information about Octave is also available on the WWW
at https://www.octave.org and via the help@octave.org
mailing list.


This seems to be working and is an improvement. With all of the changes to looking for help inside classdef files, is there other expected behavior that should be checked depending on whether any parts of the file have a help string?

Nicholas Jankowski <nrjank>
Group Member
Wed 20 Mar 2024 04:21:56 AM UTC, comment #5: 

Try the attached change.

(file #55869)

John W. Eaton <jwe>
Group administrator
Wed 14 Feb 2024 03:12:24 AM UTC, comment #4: 

I hadn't looked but was wondering what get_help_text might already be parsing the file to be able to do that. then it could just continue to return [text, status] with text containing the function line

Nicholas Jankowski <nrjank>
Group Member
Wed 14 Feb 2024 02:04:48 AM UTC, comment #3: 

I was imagining that it could be generated from the parse tree because that would guarantee a uniform presentation.  But, maybe it is just way easier to grab the line with keyword function on it, clean it up with a few regexp, and then store it as the docstring for the function.

Rik <rik5>
Group administrator
Wed 14 Feb 2024 12:25:22 AM UTC, comment #2: 

For .m file functions, my plan was to either grab the function text from the file when parsing or generate it from the parse tree.

I don't think we need to worry about what to do for built-in functions because all the ones we care to document should have doc strings.

Same for .oct file functions.  If you want to have something useful displayed, document your function.  There's no way we can automatically generate that info from a DEFUN or MexFunction declaration.

John W. Eaton <jwe>
Group administrator
Tue 13 Feb 2024 11:41:02 PM UTC, comment #1: 

was looking at help for this one.  it's easy enough to copy the 'which' line into the block that currently generates the error, but how would you pull the function definition? not sure of any functions that give you the function meta data like that, or enough pieces to generate a string from.  parse the file itself until you find the first 'function' line?

Nicholas Jankowski <nrjank>
Group Member
Mon 05 Feb 2024 10:43:58 PM UTC, original submission:  

This is a very small thing.  When a programmer tries help() on a function without documentation Octave emits an error that the function is undocumented.  Matlab, however, prints the function prototype which might be at least mildly useful to the programmer.

Here is a simple m-file no_doc_fcn.m that shows what I'm looking for


function y = no_doc_fcn (arg1, arg2, arg3)
end


And when I try using help() I get


octave:1> help no_doc_fcn
error: help: 'no_doc_fcn' is not documented


What would be nice is something like


'no_doc_fcn' is a function from the file /home/xxx/no_doc_fcn.m

  y = no_doc_fcn (arg1, arg2, arg3)



Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #55871:  fcn-doc-diff-2.txt added by jwe (3KiB - text/plain)
file #55869:  fcn-doc-diff.txt added by jwe (2KiB - text/plain)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2024-03-25 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2024-03-21 jwe StatusPatch Reviewed Ready For Test
        Fixed ReleaseNone 10.1.0 (current default)
        Planned ReleaseNone 10.1.0 (current default)
    2024-03-20 rik5 StatusPatch Submitted Patch Reviewed
    2024-03-20 jwe Attached File- Added fcn-doc-diff-2.txt, #55871
    2024-03-20 jwe StatusConfirmed Patch Submitted
    2024-03-20 jwe Attached File- Added fcn-doc-diff.txt, #55869
    2024-02-05 rik5 Priority5 - Normal 3 - Low

    Back to the top

    Powered by Savane 3.13-54b4.
    Corresponding source code