Skip to content

Commit 4975114

Browse files
authored
Merge pull request #8 from nifadyev/feature/#4/add-recommendation-about-type-annotations
#4: Add recommendation about type annotations
2 parents c965f61 + 8985851 commit 4975114

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
@@ -192,6 +192,13 @@ We recommend adding docstrings to functions, methods, and classes.
192192
Code is read much more than it is written.
193193

194194

195+
### Type Annotations
196+
197+
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.
198+
199+
**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.
200+
201+
195202
## About Pull Requests
196203

197204
### Creating Pull Requests

RU.md

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

193193

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

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

0 commit comments

Comments
 (0)