Skip to content

LCORE-1137: updated docstrings in quota package#942

Merged
tisnik merged 4 commits intolightspeed-core:mainfrom
tisnik:lcore-1137-updated-docstrings-in-quota-package
Dec 22, 2025
Merged

LCORE-1137: updated docstrings in quota package#942
tisnik merged 4 commits intolightspeed-core:mainfrom
tisnik:lcore-1137-updated-docstrings-in-quota-package

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Dec 22, 2025

Description

LCORE-1137: updated docstrings in quota package

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: CodeRabbitAI
  • Generated by: N/A

Related Tickets & Documents

  • Related Issue #LCORE-1137

Summary by CodeRabbit

  • Documentation

    • Expanded and clarified documentation across quota management components, detailing initialization, parameters, return semantics, and operational behavior.
  • Bug Fixes

    • Added explicit error handling for unrecognized quota limiter configurations to provide clearer feedback instead of silent failures.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 22, 2025

Walkthrough

Expanded and clarified docstrings across quota-related modules (QuotaExceedError, QuotaLimiter, RevokableQuotaLimiter, QuotaLimiterFactory). Added explicit error handling in QuotaLimiterFactory.create_limiter to raise ValueError for unrecognized limiter types; no other behavioral changes.

Changes

Cohort / File(s) Summary
Docstring expansions
src/quota/quota_exceed_error.py, src/quota/revokable_quota_limiter.py, src/quota/quota_limiter.py
Expanded and clarified docstrings for classes and methods (parameters, return values, semantics). No signature or control-flow changes.
Factory: docs + explicit error
src/quota/quota_limiter_factory.py
Enhanced docstrings and added explicit error handling: create_limiter now raises ValueError for unknown limiter types. No other behavioral changes.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Review the new ValueError branch in src/quota/quota_limiter_factory.py to confirm the condition and message are correct and consistent with callers.
  • Skim docstring changes in src/quota/quota_limiter.py and src/quota/revokable_quota_limiter.py for accuracy against implemented behavior, paying attention to connect / connected semantics and any described error propagation.

Possibly related PRs

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: updating docstrings across the quota package modules.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (3)
src/quota/quota_exceed_error.py (1)

16-27: Inconsistent indentation in docstring sections.

The Parameters and Attributes sections have inconsistent indentation. Some entries use 8 spaces (subject_id, available, needed) while subject_type uses 4 spaces. Per Google Python docstring conventions, all parameter descriptions should align consistently.

🔎 Proposed fix for consistent indentation
         Parameters:
-                subject_id (str): Identifier of the subject (user id or cluster id).
-            subject_type (str): Subject kind: "u" for user, "c" for cluster,
-                                any other value treated as unknown.
-                available (int): Number of tokens currently available to the subject.
-                needed (int): Number of tokens required; defaults to 0.
+            subject_id (str): Identifier of the subject (user id or cluster id).
+            subject_type (str): Subject kind: "u" for user, "c" for cluster,
+                any other value treated as unknown.
+            available (int): Number of tokens currently available to the subject.
+            needed (int): Number of tokens required; defaults to 0.
 
         Attributes:
-                subject_id (str): Copied from the `subject_id` parameter.
-                available (int): Copied from the `available` parameter.
-                needed (int): Copied from the `needed` parameter.
+            subject_id (str): Copied from the `subject_id` parameter.
+            available (int): Copied from the `available` parameter.
+            needed (int): Copied from the `needed` parameter.
src/quota/revokable_quota_limiter.py (1)

111-119: Inconsistent indentation in Parameters section.

The subject_id parameter description has inconsistent indentation compared to similar docstrings in this file.

🔎 Proposed fix
         Parameters:
-                subject_id (str): Identifier of the subject whose quota will be
-                revoked. If the limiter's `subject_type` is `"c"`, this value
-                is ignored and treated as an empty string.
+            subject_id (str): Identifier of the subject whose quota will be
+                revoked. If the limiter's `subject_type` is `"c"`, this value
+                is ignored and treated as an empty string.
src/quota/quota_limiter.py (1)

162-169: Use Python boolean literals in docstring.

The return description uses lowercase true/false instead of Python's canonical True/False boolean literals.

🔎 Proposed fix
     def connected(self) -> bool:
         """Check if connection to quota limiter database is alive.
 
         Determine whether the storage connection is alive.
 
         Returns:
-            `true` if the connection is alive, `false` otherwise.
+            bool: True if the connection is alive, False otherwise.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd795b3 and 927778c.

📒 Files selected for processing (4)
  • src/quota/quota_exceed_error.py
  • src/quota/quota_limiter.py
  • src/quota/quota_limiter_factory.py
  • src/quota/revokable_quota_limiter.py
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.py: Use absolute imports for internal modules in LCS project (e.g., from auth import get_auth_dependency)
All modules must start with descriptive docstrings explaining their purpose
Use logger = logging.getLogger(__name__) pattern for module logging
All functions must include complete type annotations for parameters and return types, using modern syntax (str | int) and Optional[Type] or Type | None
All functions must have docstrings with brief descriptions following Google Python docstring conventions
Function names must use snake_case with descriptive, action-oriented names (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying input parameters
Use async def for I/O operations and external API calls
All classes must include descriptive docstrings explaining their purpose following Google Python docstring conventions
Class names must use PascalCase with descriptive names and standard suffixes: Configuration for config classes, Error/Exception for exceptions, Resolver for strategy patterns, Interface for abstract base classes
Abstract classes must use ABC with @abstractmethod decorators
Include complete type annotations for all class attributes in Python classes
Use import logging and module logger pattern with standard log levels: debug, info, warning, error

Files:

  • src/quota/revokable_quota_limiter.py
  • src/quota/quota_limiter_factory.py
  • src/quota/quota_limiter.py
  • src/quota/quota_exceed_error.py
🧬 Code graph analysis (1)
src/quota/quota_limiter.py (3)
src/quota/revokable_quota_limiter.py (3)
  • revoke_quota (110-128)
  • increase_quota (154-174)
  • _initialize_tables (301-315)
src/models/config.py (2)
  • SQLiteDatabaseConfiguration (156-163)
  • PostgreSQLDatabaseConfiguration (176-260)
src/quota/token_usage_history.py (2)
  • _initialize_tables (184-201)
  • connect (65-93)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: build-pr
  • GitHub Check: E2E: server mode / ci
  • GitHub Check: E2E: library mode / vertexai
  • GitHub Check: E2E: server mode / vertexai
  • GitHub Check: E2E: library mode / azure
  • GitHub Check: E2E: server mode / azure
  • GitHub Check: E2E: library mode / ci
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-on-pull-request
🔇 Additional comments (8)
src/quota/revokable_quota_limiter.py (4)

36-49: LGTM!

The __init__ docstring is well-structured and follows Google Python docstring conventions with clear parameter descriptions.


58-94: LGTM!

The docstrings for available_quota and _read_available_quota are well-structured with clear parameter descriptions, return values, and behavior explanations.


131-189: LGTM!

The docstrings for _revoke_quota, increase_quota, and _increase_quota are well-formatted with clear descriptions of parameters and behavior.


231-330: LGTM!

The docstrings for consume_tokens, _consume_tokens, _initialize_tables, and _init_quota are well-structured and follow Google Python docstring conventions.

src/quota/quota_limiter_factory.py (2)

24-31: LGTM!

The enhanced docstring for quota_limiters properly documents the parameters and return values.


65-89: Good addition of explicit error handling.

The ValueError for unrecognized limiter_type values is a good improvement that provides clear feedback when misconfigured. The docstring properly documents this behavior in the Raises section.

src/quota/quota_limiter.py (2)

54-103: LGTM!

The docstrings for available_quota, revoke_quota, increase_quota, and consume_tokens are well-structured and follow Google Python docstring conventions with clear parameter and return descriptions.


107-146: LGTM!

The docstrings for __init__, _initialize_tables, and connect are comprehensive and properly document attributes, behavior, and error propagation.

@tisnik tisnik force-pushed the lcore-1137-updated-docstrings-in-quota-package branch from 927778c to c622634 Compare December 22, 2025 09:16
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (3)
src/quota/revokable_quota_limiter.py (3)

36-49: Docstring parameter continuation lines could be better aligned.

Some continuation lines in this docstring are not indented under the description text (e.g., lines 42, 44, 47-48). For consistency with other docstrings in this file (like _revoke_quota on lines 137-140), consider aligning continuations.

🔎 Suggested alignment
         Parameters:
-            configuration (QuotaHandlersConfiguration): Configuration object
-            containing `sqlite` and `postgres` connection settings.
-            initial_quota (int): The starting quota value assigned when a
-            subject's quota is initialized or revoked.
+            configuration (QuotaHandlersConfiguration): Configuration object
+                containing `sqlite` and `postgres` connection settings.
+            initial_quota (int): The starting quota value assigned when a
+                subject's quota is initialized or revoked.
             increase_by (int): Number of quota units to add when increasing a subject's quota.
-            subject_type (str): Identifier for the kind of subject the limiter
-            applies to (e.g., user, customer); when set to "c" the limiter
-            treats subject IDs as empty strings.
+            subject_type (str): Identifier for the kind of subject the limiter
+                applies to (e.g., user, customer); when set to "c" the limiter
+                treats subject IDs as empty strings.

111-119: Inconsistent indentation in Parameters section.

Lines 116-118 use 8-space indentation instead of the 4-space standard used elsewhere in this file (e.g., _revoke_quota at lines 137-140).

🔎 Suggested fix
         Parameters:
-                subject_id (str): Identifier of the subject whose quota will be
-                revoked. If the limiter's `subject_type` is `"c"`, this value
-                is ignored and treated as an empty string.
+            subject_id (str): Identifier of the subject whose quota will be
+                revoked. If the limiter's `subject_type` is `"c"`, this value
+                is ignored and treated as an empty string.

200-213: Inconsistent indentation in Parameters and Raises sections.

Lines 206-208 and 211-212 use 8-space indentation instead of 4-space, inconsistent with other docstrings in this file.

🔎 Suggested fix
         Parameters:
-                subject_id (str): Identifier of the subject to check. If this
-                limiter's `subject_type` is `"c"`, the value is ignored and
-                treated as an empty string.
+            subject_id (str): Identifier of the subject to check. If this
+                limiter's `subject_type` is `"c"`, the value is ignored and
+                treated as an empty string.
 
         Raises:
-                QuotaExceedError: If the available quota for the subject is
-                less than or equal to zero.
+            QuotaExceedError: If the available quota for the subject is
+                less than or equal to zero.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 927778c and c622634.

📒 Files selected for processing (1)
  • src/quota/revokable_quota_limiter.py
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

src/**/*.py: Use absolute imports for internal modules in LCS project (e.g., from auth import get_auth_dependency)
All modules must start with descriptive docstrings explaining their purpose
Use logger = logging.getLogger(__name__) pattern for module logging
All functions must include complete type annotations for parameters and return types, using modern syntax (str | int) and Optional[Type] or Type | None
All functions must have docstrings with brief descriptions following Google Python docstring conventions
Function names must use snake_case with descriptive, action-oriented names (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying input parameters
Use async def for I/O operations and external API calls
All classes must include descriptive docstrings explaining their purpose following Google Python docstring conventions
Class names must use PascalCase with descriptive names and standard suffixes: Configuration for config classes, Error/Exception for exceptions, Resolver for strategy patterns, Interface for abstract base classes
Abstract classes must use ABC with @abstractmethod decorators
Include complete type annotations for all class attributes in Python classes
Use import logging and module logger pattern with standard log levels: debug, info, warning, error

Files:

  • src/quota/revokable_quota_limiter.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (7)
  • GitHub Check: build-pr
  • GitHub Check: E2E: library mode / ci
  • GitHub Check: E2E: library mode / vertexai
  • GitHub Check: E2E: library mode / azure
  • GitHub Check: E2E: server mode / vertexai
  • GitHub Check: E2E: server mode / ci
  • GitHub Check: E2E: server mode / azure
🔇 Additional comments (7)
src/quota/revokable_quota_limiter.py (7)

79-94: LGTM!

Well-structured docstring with proper indentation and clear explanation of the initialization fallback behavior.


130-141: LGTM!

Properly formatted docstring with correct indentation and alignment.


176-189: LGTM!

Clear documentation of the SQL parameter ordering and transaction behavior.


224-243: LGTM!

Comprehensive docstring clearly explaining token consumption behavior and subject type normalization.


265-287: LGTM!

Good use of the Notes section to clarify the negative increment behavior.


301-307: LGTM!

Clear and concise documentation.


317-330: Good documentation of the initialization behavior.

Minor: Lines 328-329 have the same continuation alignment pattern as noted in other docstrings.

@tisnik tisnik merged commit 51dfd24 into lightspeed-core:main Dec 22, 2025
19 of 27 checks passed
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.

1 participant