Skip to content

Modernize type annotations #110

@chuckwondo

Description

@chuckwondo

Numerous type annotation enhancements have been made for both simplifying and specifying (i.e., being more specific and helpful for static analysis) such annotations up through our current minimum Python version of 3.12.

We should do the following (not necessarily exhaustive list):

  • Replace Dict, List, Tuple, Type with dict, list, tuple, type
  • Replace Union with |
  • Replace Optional[X] with X | None
  • Use **P (ParamSpec) for decorator functions so that the decorators "pass through" the signature of the decorated functions, making it easy to see the param types and return type in code completion.
  • Import Callable, Mapping, Sequence, and other "collection" types from collections.abc rather than from typing (python 3.10 deprecated importing these from typing in favor of collections.abc)
  • Replace Dict (dict) type with Mapping, where possible (i.e., where a dependency does not prevent it), as Mapping is less problematic with type variance since it is an immutable type (we should generally prefer immutable over mutable types for this reason, among others)
  • Replace List (list) type with tuple, Sequence, or Iterable (as appropriate) for same reasons as previous point.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions