Skip to content

Commit 8985851

Browse files
committed
Add recommendation about type annotations
1 parent abfb19e commit 8985851

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

EN.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ We recommend adding docstrings to functions, methods, and classes.
186186
Code is read much more than it is written.
187187

188188

189+
### Type Annotations
190+
191+
Annotating new code is strongly encouraged. Existing codebase is recommended to annotate gradually. It is also advised to use `static type checker` on `pre-commit` or `CI` stage but allow proceeding with invalid annotations because sometimes it takes a lot of effort to debug and annotate code.
192+
193+
**Why?** Typed code is better self-documented. There is no need to guess the object's type or use `isinstance`, modern IDEs work perfectly with annotated object types. Moreover, annotations reduce error rate. Warnings and errors are shown by `static type checker` during coding instead of catching errors on running project. Unit testing is also much easier if you know what types are expected.
194+
195+
189196
## About Pull Requests
190197

191198
### Creating Pull Requests

RU.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ from some.absolute.path import foo, bar
186186
Код читается намного больше, чем пишется.
187187

188188

189+
### Аннотации типов
190+
191+
Крайне рекомендуется типизировать новый код. Существующую кодовую базу следует типизировать постепенно. Не будет лишним использовать `статический анализатор типов` на стадии `pre-commit` и/или `CI` с возможностью пропустить проверку, так как зачастую требуется много времени для типизирования и отладки кода.
192+
193+
**Почему?** Типизированный код является актуальной "документацией". Не нужно угадывать тип объекта или использовать `isinstance`, современные IDE прекрасно считывают тип аннотированных объектов. К тому же типизированный код снижает число ошибок. Предупреждения и ошибки о неправильном типе возникают при запуске `статического анализатора типов` во время написания кода, а не в процессе взаимодействия с запущенным проектом. Юнит тесты писать гораздо проще, если знать, какие типы данных ожидаемы.
194+
195+
189196
## Про Pull Request
190197

191198
### Создание Pull Request

0 commit comments

Comments
 (0)