Repository navigation
Conversation
Collects every public API documentation gap at the working tree and at a base git ref with griffe, and reports only the gaps the branch introduces. Three rules: a public module, class, function or method with no docstring, a parameter with no entry in an Args: section, and a function whose return annotation is not None with no Returns: or Yields: section. Comparing rather than measuring against a threshold lets the repository adopt the check while gaps remain, and still refuses a pull request that adds a new one.
Covers each of the three rules, the cases that must not be reported (private members, dunder methods other than __init__, an unannotated return, self and cls), the convention that constructor parameters are documented on the class docstring, and the skip list for generated trees.
The job needs the same git setup as public-symbols-check, because the checker loads the base ref: full history and a local main. It carries its own label, Approve Docstring check, so that approving a public API change does not also waive the docstring gate.
The check now reports every documentation gap in the public API rather than the set difference against a base ref, so existing undocumented code fails it too. There are 1369 gaps at 3462000: 987 missing-docstring, 242 undocumented-parameter, 140 missing-returns. --against <ref> still subtracts the gaps of a ref, which narrows a long report to the gaps one working tree adds. It is a reading aid rather than the gate.
So that tox -e docstring-check -- --against main works.
The absolute check reads no base ref, so the job needs neither the full history nor a local main. Dropping the pull_request condition lets it run on merge groups and pushes as well, which an absolute check should.
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Adds a check that fails when a public API object is not properly documented, and wires it into CI.
The check is absolute, not a diff. It walks the whole public API and reports every gap it finds, whether the gap arrived with the branch under test or has been in the repository for years. So a pull request that adds an undocumented object fails, and a pull request that changes nothing while an existing object stays undocumented also fails.
This check does not pass on
maintoday. It reports 1369 gaps at3462000f3, and that is the point of opening it. The repository has never had a gate on documentation, which is how a large part of the public API came to carry no docstring, carry one that documents none of its parameters, or return a value it never describes. The number is the measurement; what to do about it is the decision this pull request asks for.What the check requires
Three rules, applied to the public API only:
missing-docstring: a public module, class, function or method with no docstring.undocumented-parameter: a parameter of a public function or method with no entry in anArgs:section.selfandclsare never required.missing-returns: a public function or method whose return annotation is present and is notNone, with noReturns:and noYields:section. A function with no return annotation is not asked for one, so the check does not demand documentation from code that carries no annotations at all.Constructor parameters are accepted on the class docstring rather than on
__init__.docs/conf.pydoes not setspecial-members, so an__init__docstring is never rendered, and the class docstring is what the API reference shows.What it reports today
Measured at the head of this branch, which changes no package source:
missing-docstringundocumented-parametermissing-returnsBy top-level name:
sdk445,exporter272,configuration185,test132,metrics71,trace59,codegen58,_logs39,shim35,propagators29,context14,util13,baggage9, the rest fewer than 5 each.Each gap prints on its own line, so the report is a work list:
Exit status 1. A gap is identified by the fully qualified name griffe reports as
obj.path, so moving a function to a different line does not change its identity.How to use it while the number is large
tox -e docstring-checkruns the absolute check, which is the gate.tox -e docstring-check -- --against mainsubtracts the gaps thatmainalready has, leaving only the gaps the working tree adds. That is how a contributor finds their own share of a 1369-line report. It is a reading aid; it is not what CI runs.The CI job carries the label
Approve Docstring checkas its escape hatch, rather than sharingApprove Public API check, so that approving a deliberate public API change does not also waive the docstring gate.Why griffe rather than ruff
ruff's
D1rules covermissing-docstringand nothing else. TheDOCrules that would cover the other two are all in preview as of ruff 0.16.1, the version pinned atdev-requirements.txt:23, and none of them reports a parameter that the signature has and the docstring does not. griffe is already a pinned dependency atdev-requirements.txt:2and already drivesscripts/griffe_check.pyin thepublic-symbols-checkenvironment, so this adds no new dependency and follows a pattern the repository already has.What is not checked
opentelemetry.proto,opentelemetry.proto_jsonandopentelemetry.semconvare skipped, because they are generated. Private objects are skipped, which is whatgriffe.Object.is_publicdecides. Attributes are skipped. Dunder methods other than__init__are skipped.Raises:sections are not checked. Deciding which exceptions a function is expected to document needs judgment a static walk cannot supply. If maintainers want that too, it is a fourth rule rather than a change to these three.Verification
tox -e docstring-checkat the head of this branch: exit 1, 1369 gaps, under a second.tox -e docstring-check -- --against main: exit 0, because this branch changes no package source.opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py: exit 1 naming all five gaps, one per rule plus two for the object missing a docstring entirely.tox -e test-scripts: 18 passed, of which 14 are the new tests inscripts/tests/test_docstring_checker.py. They cover each rule, every case that must not be reported, the constructor convention, and the skip list for generated trees.tox -e ruff: all five pre-commit hooks pass.tox -e lint-license-header-check,tox -e spellcheck,tox -e public-symbols-check: pass.tox -e generate-workflows: leaves no diff, so thegenerate-workflowsjob will not report.github/workflows/misc.ymlout of date.The decision this asks for
Merging this as it stands makes CI red until the 1369 gaps are closed, which is not something to do by accident. Three ways to land it, and I will do whichever maintainers prefer:
Approve Docstring checkuntil the count reaches zero.--against main, so it fails only on new gaps, and flip it to absolute once the existing ones are closed. This is what the first revision of this pull request did; the commits are still in the history if that is the preferred shape.