feat: implement dataclasses support for voluptuous schemas - #533
Conversation
Resolves GitHub issue alecthomas#409 by adding comprehensive dataclasses support: Features: - DataclassSchema class for automatic schema creation from dataclasses - create_dataclass_schema() function for functional API - is_dataclass() utility for dataclass detection - Automatic type validation from dataclass field annotations - Support for default values and default_factory functions - Seamless integration with existing voluptuous validators - Type annotation handling for List[T], Optional[T], etc. - Full backward compatibility with existing schemas Implementation: - Added voluptuous/dataclasses_support.py with core functionality - Added comprehensive test suite (19 tests covering all scenarios) - Added examples/dataclasses_example.py with usage examples - Updated README.md with documentation and examples - Integrated into main voluptuous module with graceful fallback Code Quality: - All tests pass (162 existing + 19 new = 181 total) - Zero flake8 violations - Zero mypy type errors - Black and isort formatting applied - Requires Python 3.7+ for dataclasses support Breaking Changes: None Backward Compatibility: Full
|
This is a great addition, and apologies for the (epic) delay in reviewing. I'd like to merge it, but I think before we do we should just remove support for Python versions that don't support dataclasses. The last release of Python 3.6 was 2021, so we should remove support for older versions (and 2.x), and then get rid of all the conditional logic in this PR. |
…legacy compatibility code
I'm bringing an update, as you pointed out; additionally, I've found a few places where code was checking older Python versions. So I included changes to them in the same PR too. I know it's antipattern, but will you accept such a change, or should I split it into smaller and separate PRs? |
|
Totally fine, thank you very much! |
Resolves GitHub issue #409 by adding comprehensive dataclasses support:
Features:
Implementation:
Code Quality:
Breaking Changes: None
Backward Compatibility: Full