Skip to content

Commit

Permalink
develop: document Python typing choices (#697)
Browse files Browse the repository at this point in the history
  • Loading branch information
slint authored and kpsherva committed Sep 26, 2024
1 parent 95cfab5 commit efb4bd4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion docs/develop/getting-started/code-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ InvenioRDM follows Invenio practices:
- Logical: Commits should be logical chunks of works (git rebase is your friend). Do not make many small commits.
- Coding style: PEP8, isorting (checked by the ``./run-tests.sh`` script and ``.editorconfig`` helps you configure your editor)
- Follow existing style (look at the module you are working on):
- Support Python 3.9+ (i.e. any officially supported Python version)
- Do not use type hints.
- Support Python 3.7+ (i.e. any supported Python version)
- **Why?** Primarily for consistency across the codebase. Having some modules with type hints and others without would make the code harder to read and maintain.
- Before we introduce type hints, as a community we would need to decide on:
- Where do we apply type hints, e.g., everywhere or only in public API functions/classes/methods
- What rules we would enforce via type linters and how specific or generic the types should be, especially with complex inheritance patterns or dynamically computed classes
- Ensuring all developers and reviewers are familiar with typing conventions and enforce them during PR reviews.
- Minimum Python versions. Typing syntax has evolved, and newer features are not backward-compatible with older Python versions. For example, Python 3.10+ allows the use of the `|` operator for unions, while older versions require `typing.Optional` or `typing.Union`. Introducing type hints would also require decisions on the minimum Python version supported so that we can work with a compelling set of typing primitives.
- We agree on and understand that Python typing annotations can be useful though, especially when it comes to showing autocompletions in your editor and linters catching bugs. We shouldn't sacrifice readability and simplicity though for typing, since Python is still a dynamically typed language and cannot take advantage of performance benefits or compilation correctness from its types.

In doubt if something is allowed or not? Just ask on Discord

Expand Down

0 comments on commit efb4bd4

Please sign in to comment.