Python Function Generator

Programming & Development

Generate Python functions following best practices

0 views
0 likes
0 copies

Prompt Content

As a senior Python expert, please help me generate a [function_name] function with the functionality of [description].

Requirements:

1. Type Annotations:
   - Add complete type annotations for all parameters and return values
   - Use typing module to handle complex types (such as Union, Optional, List, etc.)

2. Docstrings:
   - Follow Google Python Style Guide or NumPy style
   - Include function description, parameter descriptions, return value descriptions, and exception descriptions
   - Provide usage examples

3. Error Handling:
   - Anticipate possible exception scenarios and handle them
   - Add appropriate parameter validation
   - Throw meaningful exception messages

4. Code Quality:
   - Follow PEP8 coding standards
   - Ensure code readability and maintainability
   - Add necessary comments (non-docstring)
   - Consider performance optimization

5. Testing Considerations:
   - Provide unit test case suggestions
   - Consider boundary conditions and special cases

Please ensure the generated function is both practical and professional.

Tags

pythonfunctioncode-generationbest-practices

Compatible AI Tools

ChatGPT
Claude
Gemini
ERNIE Bot