Type annotations in metadata mappings
- Jan 06, 2023
-
-
Kartik Ohri authored0cea8313
-
Kartik Ohri authoreda2b39603
-
Kartik Ohri authored
Summary: Add type annotations to files in swh/indexer/metadata_dictionary/ (T2259) This patch adds type annotations to metadata mappings so that the mypy type checker can detect bugs in code. While working on the path, I also encountered these issues: 1) TypedDict does not support using variables in defining or assigning keys. At a lot of places, the code uses SCHEMA_URI to construct the keys. mypy raises errors at these places. There is a tradeoff between replacing SCHEMA_URI with its literal value everywhere and using type: ignore hints. 2) mypy raises error on detecting for implicit None returns, so I had to add return None at many places. 3) At a few places, @property s' are accessed using `cls`. mypy rightfully raises an error, so I had to add ignore to silence it for now. It appears Python 3.9+ supports class level properties so the ignores could be replaced by the proper handling when the minimum python version is raised. Closes T2259. Reviewers: vlorentz
d1924d32
-