Utilities

r2x_core.utils.filter_valid_kwargs(func, kwargs)[source]

Filter kwargs to only include valid parameters for the given function.

Parameters:
  • func (Callable[[...], Any])

  • kwargs (dict[str, Any])

Return type:

dict[str, Any]

r2x_core.utils.validate_file_extension(path, info)[source]

Validate that the file path has a supported extension.

This is a Pydantic validator that checks if the file extension from the provided path exists as a key in the module-level EXTENSION_MAPPING.

Parameters:
  • value (str) – The file path string to validate, provided by Pydantic.

  • info (pydantic.ValidationInfo) – Pydantic’s validation context. Required by the validator signature but not used in this function.

  • path (Path)

Returns:

The original file path string if its extension is valid.

Return type:

Path

Raises:
  • AssertionError – If the input value is not a string.

  • ValueError – If the file path has no extension.

  • KeyError – If the file’s extension is not found in EXTENSION_MAPPING.

Notes

This function is intended for use as a Pydantic model validator (e.g., with @field_validator or AfterValidator) and should not be called directly.