Skip to content

fix: migrate _check_types from typeguard to pydantic validate_call#1040

Merged
jonbrenas merged 8 commits intomalariagen:masterfrom
31puneet:fix/issue-484-pydantic-validate-call
Mar 30, 2026
Merged

fix: migrate _check_types from typeguard to pydantic validate_call#1040
jonbrenas merged 8 commits intomalariagen:masterfrom
31puneet:fix/issue-484-pydantic-validate-call

Conversation

@31puneet
Copy link
Copy Markdown
Contributor

@31puneet 31puneet commented Mar 4, 2026

Overview

Relates to #484

This PR migrates the _check_types runtime parameter validation from typeguard.check_type() to Pydantic v2's validate_call(), as proposed in the issue.

What this PR does

  • Replaces the typeguard-based type checking logic in _check_types with Pydantic v2's validate_call()
  • Uses validate_call(config=ConfigDict(strict=True, arbitrary_types_allowed=True), validate_return=False) to validate input types without coercing arguments
  • Adds pydantic >= 2.0.0 as a dependency
  • Preserves existing custom error message format (TypeError with parameter name, value, expected/actual types)
  • Replaces silent except Exception: pass with warnings.warn() for unsupported type annotations

Impact

  • No changes to public API — all existing @_check_types decorators work unchanged
  • typeguard dependency retained for now — still used by the pytest plugin and suppress_type_checks in tests
  • Adding Field()-based numeric constraints can be addressed in a follow-up PR if desired

@31puneet 31puneet force-pushed the fix/issue-484-pydantic-validate-call branch from f644219 to 728333a Compare March 4, 2026 16:43
@31puneet 31puneet marked this pull request as draft March 4, 2026 16:45
@31puneet 31puneet force-pushed the fix/issue-484-pydantic-validate-call branch 3 times, most recently from 1cf0705 to 8b3da14 Compare March 4, 2026 16:57
@31puneet 31puneet marked this pull request as ready for review March 4, 2026 17:35
@31puneet 31puneet force-pushed the fix/issue-484-pydantic-validate-call branch from 8b3da14 to 76e7c27 Compare March 19, 2026 16:37
@31puneet 31puneet changed the title fix: migrate _check_types from typeguard to pydantic TypeAdapter (#484) fix: migrate _check_types from typeguard to pydantic validate_call Mar 19, 2026
@31puneet
Copy link
Copy Markdown
Contributor Author

Hi @jonbrenas
Requesting a review for this PR
Issue #484 also mentions using Pydantic's Field (e.g. Field(ge=0, le=1)) for numerical constraints. Since this requires updating many methods would you prefer me to make those changes or should we keep this PR focused on the validate_call()

@31puneet
Copy link
Copy Markdown
Contributor Author

31puneet commented Mar 20, 2026

Hi @jonbrenas Could you take a look on this

@31puneet
Copy link
Copy Markdown
Contributor Author

Hi @jonbrenas PTAL

@jonbrenas jonbrenas merged commit 43198f3 into malariagen:master Mar 30, 2026
8 checks passed
@31puneet 31puneet deleted the fix/issue-484-pydantic-validate-call branch March 30, 2026 08:42
@31puneet 31puneet restored the fix/issue-484-pydantic-validate-call branch April 22, 2026 12:18
@31puneet 31puneet deleted the fix/issue-484-pydantic-validate-call branch April 22, 2026 14:11
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