1Documentation standards for PETSc4py 2==================================== 3 4Subject to exceptions given below, new contributions to PETSc4py **must** 5include `type annotations <python:typing>` for function parameters and results, 6and docstrings on every class, function and method. 7 8The documentation should be consistent with the corresponding C API 9documentation, including copying text where this is appropriate. More in-depth 10documentation from the C API (such as extended discussions of algorithmic or 11performance factors) should not be copied. 12 13Docstring standards 14------------------- 15Docstrings are to be written in `numpydoc:format` format. 16 17The first line of a function or method docstring must be a short description of 18the method in imperative mood ("Return the norm of the matrix.") "Return" is 19to be preferred over "Get" in this sentence. A blank line must follow this 20description. 21 22If the corresponding C API documentation lists a function as being collective, 23then this information must be repeated on the next line of the docstring. E.g. 24"Not collective.", "Logically collective on X.", "Collective." 25 26The initial description section can contain more information if this is useful. 27In particular, if there is a PETSc manual chapter about a class, then this 28should be referred to from here. 29 30Use double backticks around literals (like strings and numbers). E.g. 31\`\`2\`\`, \`\`"foo"\`\`. 32 33Reference PETSc functions simply using backticks. eg: `petsc.KSP`. refers to 34the PETSc C documentation for KSP. Do **not** use URLs in docstrings. Always 35use Intersphinx references. 36 37The following sections describe the use of numpydoc sections. Other sections 38allowed by numpydoc may be included if they are useful. 39 40Parameters 41.......... 42 43This is required unless there are no parameters, or it will be completely 44obvious to even a novice user what the parameters do. 45 46Types should only be specified in this section if for some reason the types 47provided by typing prove to be inadequate. If no type is being specified, do 48not include a colon (``:``) to the right of the parameter name. 49 50Use `Sys.getDefaultComm` when specifying the default communicator. 51 52Returns 53....... 54 55This should only be specified if the return value is not obvious from the 56initial description and typing. 57 58If a "Returns" section is required, the type of the returned items *must* be 59specified, even if this duplicates typing information. 60 61See Also 62........ 63 64If any of the following apply, then this section is required. The order of 65entries is as follows. Other links are permitted in this section if they add 66information useful to users. 67 68Every ``setFromOptions`` must include the link \`petsc_options\`. 69 70Any closely related part of the PETSc4py API not already linked in the 71docstring should appear (e.g. setters and getters should cross-refer). 72 73If there is a corresponding C API documentation page, this must be linked from 74the "See also" section. E.g. \`petsc.MatSetValues\`. 75 76End docstring with an empty line - "closing three quotation marks must be on a 77line by itself, preferably preceded by a blank line" 78 79.. warning:: 80 81 The docstrings must not cause Sphinx warnings. 82 83 84Type hint standards 85------------------- 86 87If returning ``self``, use ``-> Self`` in function signature. 88 89Type hints are not required when the static type signature includes a PETSc 90type (e.g. ``Vec x``). These will be automatically generated. This will also 91work for ``= None``. When using type hints, use spacing around the equals in 92any ``= None``. 93 94Communicators in type signatures must use Python typing instead of c-typing 95(i.e. ``comm: Comm`` not ``Comm comm``). This is because communicators 96can come from ``mpi4py`` and not just the ``petsc4py.PETSc.Comm`` class. 97 98For petsc4py native types that are can be strings, the type is ``argument: 99KSP.Type | str`` (not eg: ``KSPType argument``). If the type is strictly an 100enum the ``| str`` can be omitted. Full signature example:: 101 102 def setType(self, ksp_type: KSP.Type | str) -> None: 103 104If a NumPy is returned, use ``ArrayInt``/``ArrayReal``/``ArrayScalar`` as the 105return type. 106