
- A simple Employee class with type hints and validation
- A data-processing method (
process_stock_data) that operates on a pandas DataFrame - A module-level validation utility (
validate_trading_parameters) - Pytest-based tests for the processing function and the validator
Use comment-driven generation to create boilerplate quickly, then inspect and refine the generated code. Never blindly accept generated code without understanding it.
What you’ll find in this example
main.py
This module provides a minimal, well-typed implementation that includes:- An
Employeeclass with validated attributes (name,age,salary) process_stock_datamethod that:- Calculates 50-day and 200-day simple moving averages (SMA_50, SMA_200)
- Computes daily returns and 50-day rolling volatility
- Produces simple trading signals: 1 (bullish), -1 (bearish), 0 (neutral)
- A
validate_trading_parametershelper to assert basic order parameters - A small demo guarded by
if __name__ == "__main__"to show usage
test_main.py
This lightweight pytest module demonstrates how to test the validator and the processing function. The tests focus on expected behavior and error handling rather than asserting precise numeric values for large rolling windows (50, 200) when using very small datasets.AI-generated code can be helpful for scaffolding, but it may miss domain-specific edge cases. Always write unit tests, review type safety, and validate behavior on realistic datasets before deploying.
How to use this workflow
- Write clear, intent-revealing comments that describe function inputs, outputs, and edge cases you care about.
- Use comment-driven generation to quickly scaffold classes, functions, and tests.
- Manually review generated code for correctness, style, and security issues.
- Extend the generated tests to cover boundary conditions, error paths, and performance characteristics.
- Iterate: refine prompts and regenerate when scaffolding doesn’t meet requirements.