Skip to content

Add type annotations to Admin and AdminRole models#2976

Merged
jonathangreen merged 2 commits intomainfrom
chore/add-type-annotations-admin-model
Jan 11, 2026
Merged

Add type annotations to Admin and AdminRole models#2976
jonathangreen merged 2 commits intomainfrom
chore/add-type-annotations-admin-model

Conversation

@jonathangreen
Copy link
Member

@jonathangreen jonathangreen commented Jan 9, 2026

Description

Add comprehensive type hints to all methods in the Admin and AdminRole classes in src/palace/manager/sqlalchemy/model/admin.py, enabling mypy type checking for this module.

Additional changes:

  • Added None handling for is_library_manager and is_librarian methods to fix a type error in individual_admin_settings.py where role.library (which can be None for sitewide roles) was passed to these methods
  • Added necessary imports: TYPE_CHECKING, Any, Query, and Collection (under TYPE_CHECKING to avoid circular imports)
  • Added # type: ignore comment to @validates decorator (known SQLAlchemy typing issue)
  • Removed palace.manager.sqlalchemy.model.admin from mypy exclusion list in pyproject.toml

Motivation and Context

This change improves type safety and code quality by enabling mypy static type checking for the Admin and AdminRole models. The None handling fix ensures the code correctly handles sitewide roles where library is None.

How Has This Been Tested?

  • mypy passes with no errors
  • All existing tests in tests/manager/sqlalchemy/model/test_admin.py pass (9 tests)
  • Pre-commit hooks pass

Checklist

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

@jonathangreen jonathangreen requested a review from a team January 9, 2026 23:11
@codecov
Copy link

codecov bot commented Jan 9, 2026

Codecov Report

❌ Patch coverage is 88.09524% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.81%. Comparing base (7ca295e) to head (521d2c2).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/palace/manager/sqlalchemy/model/admin.py 88.09% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2976      +/-   ##
==========================================
- Coverage   92.82%   92.81%   -0.01%     
==========================================
  Files         454      454              
  Lines       42942    42947       +5     
  Branches     5998     6000       +2     
==========================================
+ Hits        39860    39861       +1     
- Misses       2014     2016       +2     
- Partials     1068     1070       +2     

☔ 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.

Add comprehensive type hints to all methods in the Admin and AdminRole
classes, enabling mypy type checking for this module.

Changes:
- Add type annotations to all Admin class methods
- Add type annotations to all AdminRole class methods
- Add type annotations to nested lookup_hook functions
- Handle None library parameter in is_library_manager and is_librarian
- Add necessary imports (TYPE_CHECKING, Any, Query, Collection)
- Remove module from mypy exclusion list
@jonathangreen jonathangreen force-pushed the chore/add-type-annotations-admin-model branch from 8cc2a25 to 521d2c2 Compare January 11, 2026 14:41
@jonathangreen
Copy link
Member Author

Codecov is complaining about patch coverage, but the coverage gaps were pre-existing, so I think we can ignore it on this PR.

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 0fcce2e into main Jan 11, 2026
18 of 19 checks passed
@jonathangreen jonathangreen deleted the chore/add-type-annotations-admin-model branch January 11, 2026 15:13
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