PEP(Python Enhancement Proposal)은 파이썬 커뮤니티에 가이드라인이나 정보 제공 목적으로 작성된 설계 문서입니다. PEP는 인덱스 넘버로 구분하여 다양한 주제를 관리하고 있는데, PEP 8은 파이썬 코드에 대한 스타일 가이드가 정리되어 있습니다.
요약된 내용은 다음과 같습니다.
1.1 Naming Conventions
변수, 함수, 클래스 등에 적절한 이름을 지정하는 방법입니다.
Naming style
다음 표는 타입 별 제안되는 naming style을 정리한 표입니다.
| 타입 | 가이드라인 | 예시 |
|---|---|---|
| 함수, 매서드 | Use lowercase. Separate words by underscore. | divider, multiply_by_two |
| 클래스 | Start each word with a capital letter. | |
| Don’t separate words with underscores. | ||
| (Use camel, Pascal case.) | Model, FeatureBuilder | |
| 변수 | Use lowercase. Separate words by underscore. | input, target_values |
| 상수 | Use an uppercase. Separate words with underscores. | CONSTANT, API_KEY |
| 모듈 | Use lowercas. Separate words with underscores | module.py, train_module.py |
| 패키지 | Use lowercas. Don’t separate words with underscores. | package, pwcpackage |
Choosing names
naming style 뿐만 아니라 이름 선정에서 신중을 기해야 가독성을 높을 수 있습니다. 기본 적으로 해당 개체가 무엇을 의미하는지 명확하게 표현하는 것이 좋습니다.
PEP 8에는 포함되어 있지 않지만 클린코드 등에서 작명 규칙을 소개합니다.
pre-commit, formatting, linting, pytest
naming convention
docsting, type hinting