Replies: 6 comments 10 replies
-
|
I should add that the original change in #2279 said:
but this seems to have been removed (though I can't see where this was done). I should also add that the Sphinx parameter and result documentation not only covers type(-hints), but also the use, purpose and meaning of the parameters and results. What may be obvious to the designer and coder at the time they wrote the code may not be obvious to the reader of the documentation. |
Beta Was this translation helpful? Give feedback.
-
|
@kulath are you able to create a PR with your suggestions? It is hard to tell from the text what is currently in the file, and what is you proposed fix. |
Beta Was this translation helpful? Give feedback.
-
|
A few comments: Docstrings for methods in the public API are used in our documentation. They should be as detailed as required to give a good description. Sphinx style should be used. Parameters and the return value should be included. We generally group imports into 3 main sections: Python, GObject and Gramps. I don't think that an extra section for third-party python modules is very helpful. Imports can be further grouped if the developer thinks that it would be useful. Imports need not be in alphabetical order, a logical order is also acceptable and may be preferable in some cases. The use of pylint overrides is not allowed. |
Beta Was this translation helpful? Give feedback.
-
|
A question about Sphinx, docstrings and snippets: The Gramps API documentation section Useful Snippets is virtually unpopulated. How is a 'Useful Snippet' marked for indexing? |
Beta Was this translation helpful? Give feedback.
-
|
@Nick-Hall @dsblank on reflection, it would be much better to simply remove the whole “Imports Grouping” section from AGENTS.md, and just make sure it is in the Gramps Programming Guidelines in the Wiki. The section is not at all necessary for AI agents to check, and is just causing so much noise (both in AI reviews, and in PRs and discussions), and in current code is more honoured in the breach than the observance, so it can’t really be important. |
Beta Was this translation helpful? Give feedback.
-
|
@iand I think it’s still too complicated and specific for AGENTS.md. Anyway AGENTS was flagging missing comment headers, rather than out of order imports, so this wouldn’t help for AGENTS. I still prefer just removing the whole section from AGENTS. Much simpler. The first couple of sentences might do for adding to the Programming Guidelines (possibly). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
There are a few cases where I think AGENTS.md has imposed 'rules' that are getting a bit ahead of our guidelines and conventions.
(Sorry, there doesn't appear to be a way to quote this part - oh dear, the markup for Discussions is terrible)
Docstrings
All functions and methods must have docstrings. Keep them concise — a short description is almost always enough:
Use the full Sphinx format (
:param:,:type:,:returns:,:rtype:) only when the parameters or return value are non-obvious and not already expressed by type hints:Do not add verbose multi-line docstrings to simple functions, and never repeat information already expressed by the function name or type hints.
(1) The idea of concise docstrings seems to be derived from, and OK for simple interfaces like those mentioned (which are from database acces), but will not be OK for more complicated code that has significant business logic.
Just a random example from narrativeweb as I am familiar with that module:
Of course, AI will tend to apply the rules literally. I think the rules are not always appropriate.
(2) I think that all functions and methods should have Sphinx style docstrings so that they can be extracted into the Gramps API documentation https://www.gramps-project.org/docs/. In the past, people have probably been quite lazy about writing documentation for the purpose that it would be extracted into this API docs, but now with the AI guides, we might be in the situation where AI (and human interpretation of the AI guides) will tend to limit completion of the documentation, at the same time as AI will actually make it much simpler to provide better documentation. (I know I tried getting AI to review and help with docs of an addon, and it was really helpful in providing Sphinx documentation).
I made a suggestion for #2279, but I think maybe it was too late to be fully considered, or needs some discussion.
Import Grouping
Imports must be organized into sections, each preceded by a comment header of this form:
Not all sections are required — include only those that apply. Common section names used in the codebase include
Standard Python modules,GTK/Gnome modules, andGramps modules.Again, this rule has forced AI to require all imports to conform to this rule. There are about 1280 .py files in the gramps repository (according to Google AI which may be rubbish). Of those, about 284 have a Python Modules comment and 376 have a Standard Python modules comment (case ignored). This has led to a PR #2284 suggesting some 1089 file changes. I don't think the programming guidelines https://gramps-project.org/wiki/index.php/Programming_guidelines#Imports actually suggests anything about these section headers for imports.
Do we really want to make that many changes, when some of the modules may have very few, or very simple imports - the style and taste of the writer may be better than an automatic AI suggestion. (Ref Guido and hobgoblins).
Inline suppression comments such as # pylint: disable=import-outside-toplevel are not acceptable.
I agree that pylint is really useful, and can catch some errors that AI misses. However:
Again, I think that this rule is too restrictive. As an example, I have an addon where an import is only needed if debug logging is turned on, so I have put it guarded by the relevant debug test later in the code with a pylint disable comment. Similarly, there is an import that will only be needed in an edge case, so it is guarded by that edge case with a disable comment. These are just my examples, you may disagree with them or maybe you would have written them differently - that is not the point. I can understand that pylint comments like too many local variables or too many parameters or too many branches should probably NOT be disabled, because one would want to see them in pylint output. The point is that the rule in AGENTS.md is just too strict.
Beta Was this translation helpful? Give feedback.
All reactions