Skip to content

refactor: add type hints and pydantic validation schemas#35

Open
lupppig wants to merge 2 commits intoEnAccess:mainfrom
lupppig:refactor/add-type-hints-pydantic
Open

refactor: add type hints and pydantic validation schemas#35
lupppig wants to merge 2 commits intoEnAccess:mainfrom
lupppig:refactor/add-type-hints-pydantic

Conversation

@lupppig
Copy link

@lupppig lupppig commented Mar 9, 2026

Brief summary of the change made

This Pull Request introduces explicit Python typing and Pydantic validation schemas to the OpenPAYGO module.

  • pyproject.toml: Added pydantic as a core dependency.

  • openpaygo/models.py: Created strict typed schemas such as:

    • MetricsRequestData
    • MetricsDataFormat
    • MetricsHistoricalDataStep
  • openpaygo/token_encode.py, token_decode.py, token_shared.py: Added comprehensive type hints to all cryptographic generation and decoding methods.

  • openpaygo/metrics_request.py, metrics_response.py: Updated to utilize the new Pydantic models to automatically validate and strip out invalid payload variables or historical data mappings before deep processing.

Closes: #34

Are there any other side effects of this change that we should be aware of?

There should be no structural side effects to existing functionality since all internal math and logic sequences remain untouched.
However, users passing completely invalid or untyped structures (e.g., an array instead of a dictionary for a metric format) will now encounter a ValidationError at instantiation rather than an obscure TypeError or KeyError deeper in the processing stack.

Describe how you tested your changes?

  • Ran the full existing pytest suite testing token generation, encoding, and spreadsheet validations.
  • All 80 edge cases and cryptographic verification tests passed. ✅
  • Ran ruff format and ruff check linters to correct line lengths and conform 100% to the repository’s PEP8 standards.

Pull Request checklist

Please confirm you have completed any of the necessary steps below.

  • Meaningful Pull Request title and description
  • Changes tested as described above
  • Added appropriate documentation for the change
  • Created GitHub issues for any relevant follow-up/future enhancements if appropriate

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.

Provide explicit type hints and pydantic validation for robust usage

1 participant