Skip to content

feat: implement dataclasses support for voluptuous schemas - #533

Merged
alecthomas merged 4 commits into
alecthomas:masterfrom
doubledare704:feature/dataclasses-support
Jul 6, 2026
Merged

feat: implement dataclasses support for voluptuous schemas#533
alecthomas merged 4 commits into
alecthomas:masterfrom
doubledare704:feature/dataclasses-support

Conversation

@doubledare704

Copy link
Copy Markdown
Contributor

Resolves GitHub issue #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

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
@alecthomas

Copy link
Copy Markdown
Owner

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.

@doubledare704

Copy link
Copy Markdown
Contributor Author

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.

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?

@alecthomas

Copy link
Copy Markdown
Owner

Totally fine, thank you very much!

@alecthomas
alecthomas merged commit 73237e9 into alecthomas:master Jul 6, 2026
8 checks passed
@doubledare704
doubledare704 deleted the feature/dataclasses-support branch July 6, 2026 20:04
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.

2 participants