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.
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):
Dict,List,Tuple,Typewithdict,list,tuple,typeUnionwith|Optional[X]withX | None**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.Callable,Mapping,Sequence, and other "collection" types fromcollections.abcrather than fromtyping(python 3.10 deprecated importing these fromtypingin favor ofcollections.abc)Dict(dict) type withMapping, where possible (i.e., where a dependency does not prevent it), asMappingis less problematic with type variance since it is an immutable type (we should generally prefer immutable over mutable types for this reason, among others)List(list) type withtuple,Sequence, orIterable(as appropriate) for same reasons as previous point.