You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The size limit for a method or function is50 lines. Reaching the size limit indicates that the function (method) is doing too much — so decompose the actions inside the function (method).
120
+
121
+
119
122
The module size limit is300 lines. Reaching the size limit indicates that the module has received too much logic — so decompose the module into several ones.
123
+
120
124
The line length is100 characters.
121
-
Imports
125
+
126
+
127
+
### Imports
128
+
122
129
The recommended import method is absolute.
130
+
123
131
Bad ❌:
132
+
```python
124
133
# spam.py
125
134
from . import foo, bar
135
+
```
136
+
126
137
Good ✅:
138
+
```python
127
139
# spam.py
128
140
from some.absolute.path import foo, bar
129
-
Why? Because absolute import explicitly defines the location (path) of the module that is being imported. With relative imports, you always need to remember the path and calculate in your mind the location of the modules foo.py, bar.py relative to spam.py
130
-
Files __init__.py
131
-
Only write imports in__init__.py files.
132
-
Why? Because __init__.py is the last place a programmer will look when they read the code in the future.
133
-
Docstrings
141
+
```
142
+
143
+
**Why?** Because absolute import explicitly defines the location (path) of the module that is being imported. With relative imports, you always need to remember the path and calculate in your mind the location of the modules `foo.py`, `bar.py` relative to `spam.py`
144
+
145
+
146
+
### Files `__init__.py`
147
+
148
+
Only write imports in`__init__.py` files.
149
+
150
+
**Why?** Because `__init__.py`is the last place a programmer will look when they read the code in the future.
151
+
152
+
153
+
### Docstrings
134
154
We recommend adding docstrings to functions, methods, and classes.
135
-
Why? Because the programmer who sees your code for the first time will be able to quickly understand what is happening in it. Code is read much more than it is written.
136
-
About Pull Requests
137
-
Creating Pull Requests
138
-
1 Pull Request=1 issue
155
+
**Why?** Because the programmer who sees your code for the first time will be able to quickly understand what is happening in it. Code is read much more than it is written.
156
+
157
+
158
+
## About Pull Requests
159
+
160
+
### Creating Pull Requests
161
+
**1 Pull Request=1 issue**
162
+
139
163
One Pull Request must solve exactly one issue.
140
-
Why? Because it is more difficult for a reviewer to keep the context of several tasks in their head and switch between them. When a PR contains several issues, then the PR often increases and requires more time and effort for the review from the reviewer.
141
-
Refactoring and Pull Requests
164
+
165
+
**Why?** Because it is more difficult for a reviewer to keep the context of several tasks in their head and switch between them. When a PR contains several issues, then the PR often increases and requires more time and effort for the review from the reviewer.
166
+
167
+
### Refactoring and Pull Requests
142
168
Refactoring is best done in a separate Pull Request.
143
-
Why? When refactoring goes along with resolving a specific issue, the refactoring blurs the context of the issue and introduces changes that are not related to that PR.
144
-
Pull Request Size
169
+
170
+
**Why?** When refactoring goes along with resolving a specific issue, the refactoring blurs the context of the issue and introduces changes that are not related to that PR.
171
+
172
+
173
+
### Pull Request Size
145
174
The resulting PR diff should not exceed +/-600 changed lines.
Why? Because the more PR involves, the more uncontrollable it becomes, and the merge is made "with eyes closed and ears shut." Also, most reviewers will find it difficult to accept a large volume of changes at once.
154
-
About tooling
155
-
Testing (pytest)
156
-
pytest - code testing framework
157
-
Recommended config in pytest.ini:
187
+
**Why?** Because the more PR involves, the more uncontrollable it becomes, and the merge is made "with eyes closed and ears shut." Also, most reviewers will find it difficult to accept a large volume of changes at once.
[mypy](http://mypy.readthedocs.io) - checker for static typing
262
+
263
+
Recommended config `mypy.ini`:
264
+
```
211
265
[mypy]
212
266
ignore_missing_imports=True
213
267
allow_untyped_globals=True
214
268
215
269
[mypy-*.migrations.*]
216
270
ignore_errors=True
271
+
```
217
272
218
-
Pre-commit hooks (pre-commit)
219
-
pre-commit - framework for managing pre-commit hooks
220
-
Recommended config .pre-commit-config.yaml:
273
+
### Pre-commit hooks (pre-commit)
274
+
275
+
[pre-commit](https://pre-commit.com) - framework for managing `pre-commit` hooks
276
+
277
+
Recommended config `.pre-commit-config.yaml`:
278
+
279
+
```yaml
221
280
default_language_version:
222
281
python: python3.8
223
282
@@ -241,9 +300,16 @@ repos:
241
300
entry: flake8 server
242
301
language: python
243
302
types: [python]
244
-
Other
245
-
RESTAPI Documentation
246
-
The recommended documentation formatis OpenAPI. The schema for OpenAPI should be generated “on the fly” to provide API clients with fresh changes.
247
-
Why? Because it's one of the common formats for documenting REST APIs that come out of Swagger. This documentation format is supported by a large number of clients (Swagger, Postman, Insomnia Designer, and many others). Also, handwritten documentation tends to quickly become outdated, and documentation that is generated directly from the code allows you to avoid constantly thinking about updating the documentation.
303
+
```
304
+
305
+
306
+
## Other
307
+
308
+
### REST API Documentation
309
+
The recommended documentation formatis [OpenAPI](https://www.openapis.org). The schema for OpenAPI should be generated “on the fly” to provide API clients with fresh changes.
310
+
311
+
**Why?** Because it's one of the common formats for documenting REST APIs that come out of Swagger. This documentation format is supported by a large number of clients (Swagger, Postman, Insomnia Designer, and many others). Also, handwritten documentation tends to quickly become outdated, and documentation that is generated directly from the code allows you to avoid constantly thinking about updating the documentation.
0 commit comments