Skip to content
Snippets Groups Projects

Type annotations in metadata mappings

Closed Lucifer Morningstar requested to merge generated-differential-D7342-source into master
  1. Jan 06, 2023
    • Kartik Ohri's avatar
      Remove TypedDict's as per chat · 0cea8313
      Kartik Ohri authored
      0cea8313
    • Kartik Ohri's avatar
      Fix mypy issues · a2b39603
      Kartik Ohri authored
      a2b39603
    • Kartik Ohri's avatar
      Type annotations in metadata mappings · d1924d32
      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
Loading