Skip to content

Add type annotations to Credential model methods#2977

Merged
jonathangreen merged 1 commit intomainfrom
chore/credential-type-annotations
Jan 11, 2026
Merged

Add type annotations to Credential model methods#2977
jonathangreen merged 1 commit intomainfrom
chore/credential-type-annotations

Conversation

@jonathangreen
Copy link
Member

Description

Add comprehensive type annotations to the Credential model methods and enable strict mypy checking for the module.

Key changes:

  • Add type hints to lookup, lookup_by_token, lookup_and_expire_temporary_token, temporary_token_create, persistent_token_create, and __repr__ methods
  • Make token and token_type parameters non-nullable where semantically appropriate (looking up by None values is logically a bug)
  • Fix classmethod using self instead of cls in persistent_token_create
  • Fix incorrect indentation in lookup_by_patron return statement

Motivation and Context

This change improves type safety in the Credential model by:

  1. Enabling strict mypy checking (removing the module from the exclusion list)
  2. Making the API more explicit about what values are expected
  3. Catching potential bugs at type-check time rather than runtime

How Has This Been Tested?

  • All existing tests pass
  • mypy passes with no errors across the entire codebase (1017 source files)
  • Added test assertions for type narrowing on nullable fields

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

- Add comprehensive type hints to lookup, lookup_by_token,
  lookup_and_expire_temporary_token, temporary_token_create,
  persistent_token_create, and __repr__ methods
- Enable strict mypy checking for credential module by removing
  it from the exclusion list in pyproject.toml
- Make token and token_type parameters non-nullable where
  semantically appropriate (looking up by None values is a bug)
- Fix classmethod using 'self' instead of 'cls' in
  persistent_token_create
- Fix incorrect indentation in lookup_by_patron return statement
- Add test assertions for type narrowing on nullable fields
@jonathangreen jonathangreen requested a review from a team January 10, 2026 00:16
@codecov
Copy link

codecov bot commented Jan 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.81%. Comparing base (d8b8dc1) to head (c9871b8).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2977   +/-   ##
=======================================
  Coverage   92.81%   92.81%           
=======================================
  Files         454      454           
  Lines       42942    42942           
  Branches     5999     5999           
=======================================
  Hits        39857    39857           
  Misses       2016     2016           
  Partials     1069     1069           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@tdilauro tdilauro left a comment

Choose a reason for hiding this comment

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

☑️

@jonathangreen jonathangreen merged commit 7ca295e into main Jan 11, 2026
19 checks passed
@jonathangreen jonathangreen deleted the chore/credential-type-annotations branch January 11, 2026 14:30
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.

2 participants