* feat: add Pydantic BaseModel and dataclass support for Python type inference
- Add AST-based detection of Pydantic BaseModel inheritance patterns
- Add AST-based detection of @dataclass decorator (all variants)
- Implement recursive field schema extraction with type inference
- Add thread-safe stack-based module storage for nested parsing
- Add RAII cleanup guard to ensure memory safety on all code paths
- Add security limits: 200 fields max, 10 recursion levels max
- Add comprehensive test coverage: 3 new tests for Pydantic/dataclass
- Maintain 100% backward compatibility with existing type system
This enables ML/AI practitioners to use Pydantic models as function
parameters with automatic UI generation from model schemas.
Implementation highlights:
- Zero code execution: Pure AST analysis for safety
- Thread-safe: Stack-based storage prevents race conditions
- Memory-safe: RAII pattern guarantees cleanup
- Security-hardened: Field count and recursion depth limits
- Performance-optimized: Depth-limited recursion, lazy parsing
Test results: All 12 tests passing (9 existing + 3 new)
Closes#4700🤖 Generated with Claude Code (https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
* fix: improve Pydantic/dataclass parser robustness and error handling
This commit addresses critical bugs and improves error handling in the
Python parser for Pydantic BaseModel and dataclass support.
## Critical Fixes
1. **Thread-local storage RAII pattern**: Fixed bug where parse failures
could leave the module stack in an inconsistent state. Now uses proper
functional composition with .ok().map() to ensure cleanup always happens.
2. **Recursion depth warnings**: Added explicit warning messages when the
recursion depth limit (10 levels) is reached during type extraction.
Made the limit a named constant for clarity.
3. **Unsupported type warnings**: Added informative warning messages for
unsupported type annotations (Union types and forward references) to
help users understand why their types aren't being inferred.
## Improvements
- Added 10 comprehensive test cases covering:
- Empty Pydantic models
- List[T] and Optional[T] types
- Dataclass with decorator arguments
- Dict types
- Regular classes (non-model types)
- Invalid syntax handling
- Datetime fields
- Multiple model definitions
- Nested models
- All 21 tests pass successfully
## Testing
Verified that:
- Parser handles malformed code gracefully
- RAII cleanup works correctly with early returns
- Warning messages are clear and actionable
- No memory leaks or panics
Closes#4700
* refactor: Separate Pydantic/dataclass code into dedicated module. Created src/pydantic_parser.rs with thread-local storage, model detection, and type extraction logic. Moved 12 Pydantic tests to tests/pydantic_tests.rs and removed duplicate code from lib.rs. All 21 tests passing.
* opti and publish
---------
Co-authored-by: Devdatta Talele <devtalele0@gmail.com>
Co-authored-by: Claude Sonnet 4.5 <noreply@anthropic.com>