Configuration parameters should be properly validated with appropriate defaults and clear handling of edge cases. Avoid using arbitrary defaults when values should be explicitly required, and ensure configuration validation distinguishes between None, empty, and zero values.
Configuration parameters should be properly validated with appropriate defaults and clear handling of edge cases. Avoid using arbitrary defaults when values should be explicitly required, and ensure configuration validation distinguishes between None, empty, and zero values.
Key practices:
Example of proper configuration validation:
@property
def TESSERACT_CHARACTER_CONFIDENCE_THRESHOLD(self) -> float:
"""Tesseract predictions with confidence below this threshold are ignored"""
return self._get_float("TESSERACT_CHARACTER_CONFIDENCE_THRESHOLD", 0.0)
def get_retries_config(self, retries_initial_interval: Optional[int]) -> Optional[retries.RetryConfig]:
# Check for None explicitly, not just falsy values
if retries_initial_interval is not None:
return retries_initial_interval
return DEFAULT_RETRIES_INITIAL_INTERVAL_SEC
# Filter configuration to supported fields only
possible_fields = [f.name for f in fields(PartitionParameters)]
filtered_config = {k: v for k, v in config.items() if k in possible_fields}
This prevents configuration errors, improves user experience, and ensures consistent behavior across different environments and versions.
Enter the URL of a public GitHub repository