Skip to content

Conversation

@omkute10
Copy link

@omkute10 omkute10 commented Nov 9, 2025

Description

This PR enhances the Querystring class by adding proper validation for the nested_format parameter in _stringify_item(). The changes ensure that only valid nested format values ("dots" or "brackets") are accepted, improving code robustness and developer experience.

Changes

  • Added input validation for nested_format parameter at the start of _stringify_item()
  • Improved error messages to clearly indicate valid format options
  • Restructured key formatting logic for better readability and maintainability
  • Added type safety with get_args(NestedFormat) for future maintainability
  • Included defensive programming with an unreachable code path check

Testing

The following test cases should be verified:

  • Using nested_format="dots" works as expected
  • Using nested_format="brackets" works as expected
  • Invalid nested_format values raise a clear ValueError
  • Existing functionality for other parameters remains unchanged

Impact

  • Security: Prevents potential issues from invalid format values
  • Developer Experience: Clear error messages help identify issues faster
  • Maintainability: Better structured code with improved type safety
  • Future-Proof: Easier to add new nested formats if needed

Related Issues

  • Resolves TODO comment about handling unknown formats
  • Follows up on type safety improvements from previous PRs

Additional Notes

  • The changes are backward compatible
  • No breaking changes introduced
  • Documentation updates not required as this is an internal method

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.

1 participant