Skip to content

docs: complete Google-style docstring coverage (99.2% → 100%)#37

Merged
williaby merged 3 commits into
mainfrom
claude/add-library-docstrings-sxMuY
Jun 10, 2026
Merged

docs: complete Google-style docstring coverage (99.2% → 100%)#37
williaby merged 3 commits into
mainfrom
claude/add-library-docstrings-sxMuY

Conversation

@williaby

Copy link
Copy Markdown
Contributor

Summary

Audited the library against the four-step docstring brief (module / class / function & method / type hints) and filled in the only three items still missing a docstring. Every other public module, class, and function already has a Google-style docstring (Args: / Returns: / Raises:), so the diff is small and surgical — no business logic changes.

Interrogate coverage (before / after)

Measured with uvx interrogate -v src/ packages/*/src/ (interrogate 1.7.0).

Total Missing Coverage
Before 374 3 99.2 %
After 374 0 100.0 %

Items that were missing

The three nodes interrogate flagged as MISSED, all of which are now documented:

  1. src/python_libs/middleware/__init__.py — empty file, no module docstring. Added a module docstring describing the namespace package.
  2. cloudflare_auth.utils.mask_sensitive_data.mask_match (utils.py:224) — inner regex-substitution callback. Added a Google-style docstring and parameter / return type annotations (re.Match[str] -> str, using only the already-imported stdlib re module — no new dependencies).
  3. cloudflare_auth.middleware_enhanced.require_tier.dependency (middleware_enhanced.py:723) — closure returned as a FastAPI dependency. Added a docstring describing the LIMITED < FULL < ADMIN tier ordering and the HTTPException 403 raised when the user's tier is below the required minimum.

Why so few changes?

The library was already heavily documented prior to this PR:

  • All JWT files (cloudflare_auth.validators, models, middleware, middleware_enhanced) already document expected token format, validated claims, exceptions raised, and security assumptions (e.g. RS256 + Cloudflare-issued JWKS, audience/issuer validation, expiration checking).
  • All GCS files (gcs_utilities.client, exceptions) already document the bucket / key contract, the env-var configuration (GCP_SA_KEY, GCS_BUCKET, GCP_PROJECT), and the NotFoundGCSNotFoundError mapping.
  • The existing FastAPI Request parameters in csrf.validate_request and utils.get_client_ip are intentionally left un-annotated with # noqa: ANN001 because fastapi / starlette are optional extras ([project.optional-dependencies].fastapi) — adding a hard import would violate the brief's "Do not introduce new dependencies" rule. These were left as-is.

Verification

  • uvx interrogate src/ packages/*/src/PASSED (minimum: 80.0%, actual: 100.0%)
  • uv run ruff check on the changed files → All checks passed!
  • pytest tests/ in packages/cloudflare-auth111 passed
  • Smoke-tested mask_sensitive_data, sanitize_email, sanitize_for_logging end-to-end — output identical to pre-change behavior.

Test plan

  • Interrogate reports 100 % coverage
  • Ruff clean on changed files
  • cloudflare-auth test suite passes (111/111)
  • No public API surface changes (docstrings + one inner-function type annotation only)

Generated by Claude Code

…coverage

Adds the three docstrings flagged by interrogate as missing:

- src/python_libs/middleware/__init__.py: module docstring for the
  middleware namespace package (file was previously empty).
- cloudflare_auth.utils.mask_sensitive_data.mask_match: docstring and
  type annotations (re.Match[str] -> str) for the inner replacement
  callback used with re.sub.
- cloudflare_auth.middleware_enhanced.require_tier.dependency: docstring
  for the closure returned as a FastAPI dependency, describing tier
  ordering and the HTTPException raised when a user's tier is below
  the required minimum.

No behavior changes. Interrogate coverage: 99.2% -> 100.0%.
Copilot AI review requested due to automatic review settings May 15, 2026 22:43
@coderabbitai

coderabbitai Bot commented May 15, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@williaby, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 23 minutes and 1 second. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1eac055d-a0e7-4d07-b504-ae84e4ac7c1c

📥 Commits

Reviewing files that changed from the base of the PR and between 4365097 and 6737180.

📒 Files selected for processing (4)
  • CHANGELOG.md
  • packages/cloudflare-auth/src/cloudflare_auth/middleware_enhanced.py
  • packages/cloudflare-auth/src/cloudflare_auth/utils.py
  • src/python_libs/middleware/__init__.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/add-library-docstrings-sxMuY

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR completes docstring coverage across the repo by adding the remaining missing docstrings (and one inner-function type annotation) to reach 100% interrogate coverage, without changing runtime behavior.

Changes:

  • Added a module docstring for python_libs.middleware.
  • Added a docstring + re.Match[str] -> str type hints for the mask_sensitive_data regex callback.
  • Added a docstring for the require_tier() FastAPI dependency closure documenting tier ordering and raised errors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/python_libs/middleware/__init__.py Adds a new module docstring for the middleware package.
packages/cloudflare-auth/src/cloudflare_auth/utils.py Documents and types the mask_match callback used by mask_sensitive_data.
packages/cloudflare-auth/src/cloudflare_auth/middleware_enhanced.py Documents the require_tier() dependency closure behavior and errors.

Comment thread src/python_libs/middleware/__init__.py Outdated
@@ -0,0 +1,6 @@
"""Middleware components for Python Libs.

This namespace package is reserved for middleware modules (request/response
Comment on lines +227 to +232
For email-like matches (containing ``@``), masks the local and domain
parts separately. For all other matches, replaces every character
with ``*``.

Args:
match: Regex match object produced by :func:`re.sub`.
Comment on lines +724 to +738
"""Validate that the current user meets ``minimum_tier``.

Resolved as a FastAPI dependency by :func:`require_tier`. The user is
loaded from request state via :func:`get_current_user`; tiers are
ordered ``LIMITED < FULL < ADMIN``.

Args:
request: Incoming FastAPI/Starlette request.

Returns:
The authenticated :class:`CloudflareUser`.

Raises:
HTTPException: ``403`` if the user's tier is below
``minimum_tier``; ``401`` (via :func:`get_current_user`) if
claude and others added 2 commits May 15, 2026 22:47
- Rephrase middleware/__init__.py docstring: drop the inaccurate
  "namespace package" wording (a directory with __init__.py is a regular
  package per PEP 420 terminology).
- Convert the new docstrings in cloudflare_auth/utils.py and
  cloudflare_auth/middleware_enhanced.py from Sphinx/reST markup (:func:,
  :class:, ``double-backticks``) to plain Google-style prose so they
  match the surrounding docstrings in those files and render cleanly in
  non-Sphinx tooling.
- Add Documentation entry to [Unreleased] in CHANGELOG.md to satisfy
  the Changelog Check.
@williaby williaby enabled auto-merge (squash) June 10, 2026 02:41
@sonarqubecloud

Copy link
Copy Markdown

@williaby williaby merged commit 6aaba0f into main Jun 10, 2026
33 of 36 checks passed
@williaby williaby deleted the claude/add-library-docstrings-sxMuY branch June 10, 2026 02:42
williaby added a commit that referenced this pull request Jun 10, 2026
Re-resolve against current main (#36/#41/#37 landed after the first sync):
- mutation-testing.yml, scorecard.yml: take main's versions (preserve the
  already-merged #41/#36 changes; #40's per-job permission tightening on
  those two files is dropped to avoid reverting merged work).
- CHANGELOG.md: keep both the Security (this PR) and Documentation (main) sections.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
williaby added a commit that referenced this pull request Jun 10, 2026
Combine #40's security-hardening docstring content with #45's pydoclint
style (arg-type-hints-in-docstring=true), and bring the docstrings #40/#37
added into pydoclint compliance:
- validators.py: drop the __init__ docstring (DOC301; moved Raises into the
  class docstring), keep typed arg style, drop the removed verify_exp param.
- client.py: typed Returns/args, keep the empty-prefix Raises; remove the
  non-raised Exception entry from _get_or_create_bucket.
- middleware_enhanced.py / utils.py: add type hints to the dependency and
  mask_match closures' docstrings.
pydoclint: 0 violations.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants