Skip to content
This repository has been archived by the owner on Aug 14, 2024. It is now read-only.

Update backend typing section #1052

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/docs/workflow.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ apply the revert directly to the primary branch.

## Python typechecking

We're slowing working to add typing to our Python codebase, using `mypy` to check types. While we do that, there are a few useful things to know:
We're slowly working to add typing to our Python codebase, using `mypy` to check types. While we do that, there are a few useful things to know:

- As you create or work on Python files, please add typing where you can. If possible, try to follow the [Python typing best practices](https://typing.readthedocs.io/en/latest/source/best_practices.html), which may mean you also have to add `from __future__ import annotations` as the first line of your file. For more information about using types in Python, see [the typing docs](https://typing.readthedocs.io/en/latest/index.html).

- In some repos not all files currently pass a typecheck, so in those repos we're enabling checking on a file-by-file basis. (Look for a `files` entry in the `[mypy]` section of the repo's `mypy.ini` file to see if that's the case for a given repo.) This means that in those repos, adding new files and/or moving or renaming existing files may necessitate a change in the `mypy.ini` file, to add or update the files' paths. Also, if you update a file to include typing, please add it to the list!
- Check that the file you're modifying is not on the exclude list from `pyproject.toml`. In other words, you need to opt-in the file for type checking to happen.

- To test types locally, many repos have a `make` command you can run. (The exact command varies by repo. In both `sentry` and `getsentry` it is `make backend-typing`.) In repos which don't have a make command, you can run `mypy --strict --warn-unreachable --config-file mypy.ini` at the root level of the repo.
- To test types locally, you can run `mypy path/to/file` or just `mypy` to run against all files.