Skip to content

Commit bdf81d7

Browse files
committed
docs: Python conventions
1 parent 3e06174 commit bdf81d7

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

python-conventions/CONVENTIONS.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
When writing python code, you MUST follow these principles:
2+
3+
- Provide clean, production-grade, high quality code
4+
- All code should target python version 3.9+ or greater
5+
- Use well-known python design patterns and object-oriented programming approaches
6+
- Quote strings and docstrings with single-quote not double-quote
7+
- Do not modify existing whitespace
8+
- Use only single quotes for strings, do not use speech marks
9+
- Provide code blocks with proper google style docstrings
10+
- Provide code blocks with input and return value type hinting
11+
- Always use type hints
12+
- Use F-string for formatting strings
13+
- Keep functions Small: Each function should do one thing and do it well
14+
- Use List and Dictionary Comprehensions: They are more readable and efficient
15+
- Use generators for large datasets to save memory
16+
- Use logging: Avoid print statements unless displaying information on CLI for the user
17+
- Never use f-strings in logging functions; use idiomatic string formatting
18+
- Implement robust error handling when calling external dependencies
19+
- CLI should use the Click library
20+
- All dependencies are defined in pyproject.toml and not in requirements.txt
21+
- Use PEP585 and PEP604 conventions for type hints
22+
- Always pass a pytz timezone to datetime.now()
23+
- Never change unrelated whitespace
24+
- Avoid catching Exception; catch only exceptions that are expected to be raised in the try block.

python-conventions/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Python Coding Conventions
2+
3+
This conventions file provides guidelines for writing clean, maintainable Python code. The conventions emphasize readability, consistency, and following Python best practices.
4+
5+
## Purpose
6+
7+
These conventions ensure that Python code is:
8+
- Readable and self-documenting
9+
- Consistent across projects
10+
- Following PEP 8 and other Python best practices
11+
- Easy to maintain and extend
12+
- Type-safe when using type hints
13+
14+
## Use Cases
15+
16+
This convention is intended for use when:
17+
- Writing new Python applications
18+
- Maintaining existing Python codebases
19+
- Developing Python libraries and packages
20+
- Writing scripts and automation tools
21+
- Using Python with frameworks like Django, Flask, or FastAPI
22+
23+
## Usage
24+
25+
[See How to Use These Conventions](https://github.com/Aider-AI/conventions#how-to-use-these-conventions)
26+
27+
For Python-specific usage:
28+
1. Review the [CONVENTIONS.md](CONVENTIONS.md) file
29+
2. Configure your editor with Python linting tools
30+
3. Use type hints for better code safety

0 commit comments

Comments
 (0)