Welcome to the Python Code Quality Training Repository! This resource is designed to help junior engineers master clean, Pythonic code and professional development practices.
By working through this repository, you will:
- Write idiomatic Python code that follows community standards
- Master naming conventions that make code self-documenting
- Structure code using classes and OOP principles where appropriate
- Write effective tests using pytest and modern testing practices
- Develop habits that lead to maintainable, readable code
python-code-quality/
├── guides/ # Comprehensive guides with examples
│ ├── 01_pythonic_code.md
│ ├── 02_naming_conventions.md
│ ├── 03_oop_and_classes.md
│ ├── 04_testing.md
│ └── examples/ # Code examples demonstrating concepts
├── exercises/ # Hands-on coding exercises
│ ├── 01_pythonic_code/
│ ├── 02_naming_conventions/
│ ├── 03_oop_patterns/
│ └── 04_testing/
└── solutions/ # Reference solutions (try exercises first!)
-
Read the Guides: Start with the guides in order. Each builds on previous concepts.
- Guide 1: Pythonic Code Practices
- Guide 2: Naming Conventions
- Guide 3: OOP and Class Structure
- Guide 4: Testing with pytest
-
Study Examples: Review the code examples in
guides/examples/to see concepts in action. -
Complete Exercises: Work through exercises for each topic. Try to solve them without looking at solutions!
-
Check Solutions: After attempting exercises, compare your solutions with the reference implementations.
-
Apply in Real Projects: Use these principles in your daily work.
Learn Python idioms and best practices that make your code more readable and efficient.
- List comprehensions and generator expressions
- Context managers and the
withstatement - Pythonic iteration patterns
- Duck typing and EAFP principle
- Decorators and property usage
Master the art of naming variables, functions, classes, and modules.
- PEP 8 naming standards
- Meaningful and intention-revealing names
- Avoiding abbreviations and cryptic names
- Naming booleans, collections, and functions
- Module and package naming
Learn when and how to use classes effectively in Python.
- When to use classes vs functions
- Single Responsibility Principle
- Composition over inheritance
- Data classes and named tuples
- Abstract base classes and protocols
Master testing practices to write robust, maintainable code.
- Writing effective unit tests with pytest
- Using fixtures for test setup and teardown
- Mocking external dependencies
- Parametrized tests for multiple scenarios
- Test-driven development (TDD) basics
- Achieving good test coverage
Before submitting any code for review, ask yourself:
- Is my code Pythonic? (EAFP, comprehensions, context managers)
- Are all names clear and self-documenting?
- Have I avoided single-letter variables (except in comprehensions)?
- Are my functions focused and doing one thing?
- Have I used classes appropriately (not over-engineering)?
- Does my code follow PEP 8 style guidelines?
- Have I added docstrings to functions and classes?
- Is my code DRY (Don't Repeat Yourself)?
- Have I written tests for my code?
- Are my tests independent and repeatable?
Recommended Tools:
pytest- Testing frameworkpytest-cov- Code coverage toolpylint- Static code analyzerblack- Code formattermypy- Type checkerisort- Import sorter
Setup:
pip install pytest pytest-cov pylint black mypy isortRun checks:
# Testing
pytest tests/ -v
pytest --cov=src tests/
# Code quality
black --check your_file.py
pylint your_file.py
mypy your_file.py
isort --check your_file.py- PEP 8 - Style Guide for Python Code
- PEP 20 - The Zen of Python
- pytest Documentation
- Python Anti-Patterns
- Effective Python by Brett Slatkin
- Clean Code in Python by Mariano Anaya
- Python Testing with pytest by Brian Okken
If you're stuck on an exercise or concept:
- Re-read the relevant guide section
- Study the examples in
guides/examples/ - Review the Zen of Python:
python -c "import this" - Ask a senior engineer for guidance
- Check solutions as a last resort (learn from them, don't just copy!)
At Atlassian, we value:
- Readability over cleverness - Code is read more than written
- Simplicity over complexity - Simple solutions are better
- Consistency - Follow team conventions
- Documentation - Code should be self-documenting, comments explain why
- Testing - Write testable, tested code
Happy coding! Remember: writing clean code is a skill that improves with practice. 🐍✨