-
-
Notifications
You must be signed in to change notification settings - Fork 688
Docs: Show typing info and parse INPUT/OUTPUT sections #40634
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
Open
tobiasdiez
wants to merge
13
commits into
sagemath:develop
Choose a base branch
from
tobiasdiez:docs-typing
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ea0f2c8
Docs: Show typing info and parse INPUT/OUTPUT sections
tobiasdiez 5ae3584
Update conda lock files
tobiasdiez 07e8199
Revert "Update conda lock files"
tobiasdiez 740ae47
Make syntax compatible with Python 3.11
tobiasdiez a5fa8c3
Fix various syntax errors in docstrings
tobiasdiez b0916fb
Improve name sanitization and disable raising an exception if a field…
tobiasdiez 51bc72e
Temporarily disable raising warnings as errors
tobiasdiez 03ee44e
Fix more docstring issues
tobiasdiez f16b616
Improve docstring parsing
tobiasdiez 00c6223
Improve handling of examples sections
tobiasdiez bd9b771
Refine function documentation guidelines for types in INPUT and OUTPUT
tobiasdiez 3da6b69
Merge branch 'develop' into docs-typing
tobiasdiez d67d15e
Merge branch 'develop' into docs-typing
tobiasdiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -345,9 +345,25 @@ information. You can use the existing functions of Sage as templates. | |||||
|
|
||||||
| The INPUT block describes all arguments that the function accepts. | ||||||
|
|
||||||
| 1. The type names should be descriptive, but do not have to represent the | ||||||
| exact Sage/Python types. For example, use "integer" for anything that | ||||||
| behaves like an integer, rather than "int" or "Integer". | ||||||
| 1. Put type information first and foremost in the function signature | ||||||
| (Python / Cython annotations). Treat the signature as the single | ||||||
| authoritative place for ordinary type declarations. The INPUT | ||||||
| block must not restate obvious types already conveyed there. | ||||||
| Instead, use the INPUT block to document the *semantic constraints* | ||||||
| and any *non‑obvious* accepted forms: | ||||||
|
|
||||||
| - State mathematical or structural conditions: e.g. "prime integer", | ||||||
| "nonnegative", "an iterable of vertices", "a square matrix", etc. | ||||||
| - Mention coercion behavior, mutability expectations, or protocol | ||||||
| requirements ("must implement ``.degree()``", "anything with a | ||||||
| ``.parent()``"). | ||||||
| - Only include explicit type names if they add information not present | ||||||
| in the annotation (e.g. symbolic vs numeric, sparse vs dense). | ||||||
|
|
||||||
| Avoid redundant phrases like "``n`` -- integer" when the signature reads | ||||||
| ``def f(n: int, ...)``; write instead "``n`` -- nonnegative" or | ||||||
| "``n`` -- number of iterations (>= 1)". Legacy docstrings may still show | ||||||
| the old style; new and updated code should follow this convention. | ||||||
|
|
||||||
| 2. Mention the default values of the input arguments when applicable. | ||||||
|
|
||||||
|
|
@@ -394,6 +410,13 @@ information. You can use the existing functions of Sage as templates. | |||||
| to be sorted in the same way as the corresponding factors of the | ||||||
| characteristic polynomial. | ||||||
|
|
||||||
| As for INPUT, do not repeat trivial typing information in the OUTPUT | ||||||
| block. Treat the function's return annotation (or an obviously implied | ||||||
| type) as authoritative. Do NOT write just ``OUTPUT: integer`` or | ||||||
| ``OUTPUT: list`` when the signature already makes this clear (e.g., | ||||||
| ``def rank(self) -> int``). Instead, explain the semantic meaning, | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Usually we should return an |
||||||
| constraints, structure, and any subtleties. | ||||||
|
|
||||||
| - An **EXAMPLES** block for examples. This is not optional. | ||||||
|
|
||||||
| These examples are used for documentation, but they are also | ||||||
|
|
||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we have this as the recommendation for now and leave adding a type alias for
Integer | intfor follow-up? Or would you prefer to add the type alias in this PR?