Open Mews opened 1 month ago
This enhancement simplifies parameter validation in the validate_params
decorator by leveraging function type hints. It refactors existing code and test cases to extract parameter types directly from function signatures, eliminating the need for specifying types within the decorator.
Files | Change Summary |
---|---|
flask_utils/decorators.py |
Updated imports, removed a parameter from validate_params , and added functionality to use type hints in decorators. |
tests/test_validate_params.py |
Refactored test cases to specify parameter types directly in function signatures instead of within the decorator. |
sequenceDiagram
participant Client
participant FlaskApp
participant Decorator
participant Function
Client->>FlaskApp: Send request with parameters
FlaskApp->>Decorator: Call validate_params
Decorator->>Function: Extract type hints from function signature
Function-->>Decorator: Return validation results
Decorator-->>FlaskApp: Pass results
FlaskApp-->>Client: Send response
Amidst the code, a rabbit hops,
Refactoring in merry hops,
With type hints now, no room for doubt,
Validations clear, no twist nor rout.
The tests reformed, the code refined,
In flasky bounds, it's well-defined.
🎉🐇
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Description
Changed the
validate_params
decorator to get the expected types for each argument from the decorated function's type hints rather than a parameters argument. The validated arguments are then passed to the decorated function from the json data, or passed as None if they're optional and not present in the json data.I also changed the tests in
test_validate_params
to use the new syntax. I'm currently skipping the tests inTestTupleUnion
until I understand what do to to them.Related Issue
Checklist
Type of change
Summary by CodeRabbit
New Features
Bug Fixes
validate_params
decorator to improve type validation in various scenarios.Tests