Coding Conventions
The rules this repository follows are checked in, in .cursor/rules/, and they are
the specification rather than this summary. That directory listing is the authority
on which rules exist; the table below is a reading aid, and each rule file carries a
one-line description at its top.
Rule |
Covers |
|---|---|
|
Python coding style: naming, structure, typing, error handling. |
|
Test design, and how to critique a test suite. |
|
The documentation system, prose conventions, docstrings, and the Sphinx build gates. |
|
This guide’s own structure and completeness rules. |
|
The |
|
The other documentation kinds, for reference. |
|
How a pull request is written and opened. |
|
Branching and commits. |
|
Adding and pinning dependencies. |
|
Development environment and CI. |
|
Security expectations. |
|
Reporting a defect. |
What the tools enforce
Every rule that can be checked mechanically is, and
scripts/run-all-checks.sh runs the checks (see Testing for
the list and what configures each one). Three of them are worth knowing about before
writing code:
mypy runs strict over the whole repository, with no module silenced by an
ignore_errorsentry – that list is empty. What remains isexclude, for the paths that are not project source, andignore_missing_imports, for the third-party packages that ship neither annotations nor a typeshed stub. Read the current contents of both out of[tool.mypy]; each entry is documented where it sits, and counting them here would only go stale. A tree that cannot pass the checker is not a configuration problem: annotate it, or say at the site – with the reason – what the checker cannot see, which is what# type: ignore[...]is for.warn_unused_ignoresis on, so each of those has to keep earning its place.ruff’s per-file-ignores table is empty, and adding a row to it is not the way to land code that does not pass. Fix the code, or suppress the one rule on the one line with
# noqa: <CODE>and the reason, whichRUF100then keeps honest by failing when the suppression stops being needed. A handful of codes are ignored globally instead, listed inextend-ignorewith a reason for each.bandit’s skip list is one entry (
B101, the narrowing assertions the type annotations rest on); everything else is a per-line# nosec <ID> - <reason>at the statement it covers.
Deviations
One rule is deliberately waived for this repository, and it is written down where it applies rather than only here:
Public web API backwards compatibility is preserved, against the general no-back-compat policy. An OPUS URL that worked before has to keep working; the guide in Public Web API is what it has to keep matching. The one deliberate exception is
/apiguide.pdf, which redirects (302) to the published guide rather than serving a generated PDF, since the PDF is not built here; the URL still resolves, andtest_help_api.pypins the redirect.
Docstrings
Every module, class, method and function carries a docstring, in Google style with a
Parameters: section, and the API reference is generated from them – so a thin
docstring is a hole in the published documentation rather than a private matter.
There is one standing exemption, and it is deliberate: the field_obs_* methods of
the obs hierarchy do not carry individual docstrings. Each class that has them says so
once in its own docstring. The authoritative statement of what one of those methods
returns is its schema column plus the test that checks the correspondence, which is
checkable, where a thousand near-identical hand-written sentences would be a thousand
chances to be wrong.