Instructions for Backend Python Type Checks

10 views
Skip to first unread message

Sajal Asati

unread,
Aug 28, 2021, 3:50:52 PM8/28/21
to oppia-dev
Hello Oppia devs,

As part of the GSoC project “Make Backend Code Typed”, we have now fully covered `core/storage` and `core/platform` folders for backend type annotations using mypy type checker.

Now as we plan to annotate the rest of the codebase, and since we are also completing the Python3 migration alongside that, here are a few important things to take note of. These are important for both devs and code owners to keep in mind in order to maintain code quality while adding backend type annotations in future. (You can find the same info in our newly updated Type annotation wiki, but summarizing the important points here)
  1. After merging PR #13681, we have now enforced usage of only Python 3 style type annotations, and the old Py2 style annotations (which was in form of comments) is now prohibited. You can take a look at `core/storage` and `core/platform` folders to understand this syntax.
  2. The use of `Any` type and `# type: ignore[]` should be avoided as much as possible. If they are used, a proper explanation should be added as a comment on top of that code. Only exception to this is usage of `# type: ignore[no-untyped-call]`.
  3. Don’t use Text as a type, use str instead.
  4. Import types from the typing module in a single line - see point 3 here.
Important for Codeowners: Here Point 2 is very important to ensure type annotations are of high quality. It has to be taken care of manually because we do not have a lint check for it. We will have more reminder emails in future to ensure that everyone gets habitual to this practice.

Important for all devs: Please merge your existing branches from the latest develop if you have an active PR as some new lint checks were introduced recently related to adding annotations.


Thanks,
Mypy Team (Hardik, Sajal, Vojta)

Sajal Asati

unread,
Oct 25, 2021, 1:16:58 PM10/25/21
to oppia-dev
Hello Oppia devs,

As per our previous mail, we are continuing our work on making the backend code strictly typed via MyPy checks, and would like to remind you all about few points related to this.
  1. If you working on adding a new python file in the (backend part of) codebase, or making changes to an existing file with type annotations, it will have to be type annotated unless it has been put under the deny list of files in `scripts/run_mypy_checks.py` (i.e files for which MyPy checks are to be skipped).
  2. As mentioned in the previous mail in the thread, we only support usage of Python 3 styled type annotations.
  3. Please refer to our Type Annotation Wiki to understand how type annotations are to be added. We will try to keep it updated with all the hints/suggestions, so do check it now when stuck.
  4. We have a beginner issue #14033 if you would like to volunteer in adding these type annotations to the `core/domain` folder of the codebase or want a quick experience of how the process looks like. We would create more such issues in future to cover the rest of the folders.
Do reach out to MyPy team members in case of any question/suggestion.

Thanks,
Mypy Team (Hardik, Sajal, Vojta)
Reply all
Reply to author
Forward
0 new messages