Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exhaustive input validation for all callables #23

Open
knakamura13 opened this issue Oct 8, 2024 · 3 comments
Open

Add exhaustive input validation for all callables #23

knakamura13 opened this issue Oct 8, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@knakamura13
Copy link
Owner

Issue Summary
Implement automatic type-related input validation for all functions, methods, and classes with defined type hints across the project. This will ensure that every callable enforces type constraints at runtime, raising TypeError for incorrect parameter types or return types.

Describe the Request

  • Integrate a tool like pytypes or typeguard to enforce type-checking based on type hints for all functions, methods, and classes in the codebase.
  • Apply the validation at a project-wide level to avoid manually decorating individual callables.
  • Ensure that any type mismatch between actual arguments and the expected types specified in the type hints results in a TypeError to improve the reliability and robustness of the code.

Desired Outcome

  • All callables will automatically validate their inputs and outputs based on the specified type hints.
  • Any incorrect input types or invalid return types should raise a TypeError immediately, ensuring that code is strictly type-safe.
  • This will reduce potential bugs arising from incorrect types and enforce strong typing throughout the codebase.

Current State

  • The project currently has strong type hints on parameters and return values across the codebase.
  • However, type validation is not automatically enforced at runtime, meaning type mismatches can go unnoticed if they are not caught by tests.

Proposed Solution

  • Choose either pytypes or typeguard for the task:
    • Option 1: Use pytypes with set_global_typechecked(True) to activate global type checking.
    • Option 2: Use typeguard with install_import_hook('your_package_name') to enforce type checks at runtime.
  • Configure the chosen tool in the project’s main entry point (such as the top-level __init__.py file) to apply validation across all sub-modules.
  • Perform a thorough test of the implementation to ensure it doesn’t introduce significant overhead and that all callables are correctly enforcing type constraints as expected.

Future Work

  • Once type validation is fully implemented and verified, extend the input validation to include value range constraints for all applicable callables.
    • Integrate a library or custom utility to validate input ranges, raising ValueError for values that fall outside expected ranges.
    • For example, enforce constraints on numerical inputs (e.g., positive integers, bounded floats) or on specific string formats.
  • This enhancement will further improve input robustness, ensuring that callables adhere not only to type constraints but also to expected value ranges.
@knakamura13 knakamura13 self-assigned this Oct 8, 2024
@knakamura13 knakamura13 added the enhancement New feature or request label Oct 8, 2024
@knakamura13
Copy link
Owner Author

This issue depends on #24.

@knakamura13
Copy link
Owner Author

Going to try out typeguard first.

@knakamura13
Copy link
Owner Author

Used typeguard (i.e., install_import_hook('mlrose-ky') and found no issues with types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant