Description
Add generic typing to _AbstractPlotter so that Plotter2D.layers has type Dict[str, Layer2D] and Plotter3D.layers has type Dict[str, Layer3D].
Currently, layers is typed as Dict[str, Union[Layer2D, Layer3D]] which causes poor IntelliSense when accessing layers via dictionary lookup.
Implementation
- Import
TypeVar and Generic from typing
- Define
L = TypeVar("L", bound="_AbstractLayer")
- Make
_AbstractPlotter extend Generic[L]
- Type
layers as Dict[str, L]
- Update
Plotter2D to extend _AbstractPlotter[Layer2D]
- Update
Plotter3D to extend _AbstractPlotter[Layer3D]
Acceptance Criteria
Description
Add generic typing to
_AbstractPlotterso thatPlotter2D.layershas typeDict[str, Layer2D]andPlotter3D.layershas typeDict[str, Layer3D].Currently,
layersis typed asDict[str, Union[Layer2D, Layer3D]]which causes poor IntelliSense when accessing layers via dictionary lookup.Implementation
TypeVarandGenericfrom typingL = TypeVar("L", bound="_AbstractLayer")_AbstractPlotterextendGeneric[L]layersasDict[str, L]Plotter2Dto extend_AbstractPlotter[Layer2D]Plotter3Dto extend_AbstractPlotter[Layer3D]Acceptance Criteria
_AbstractPlotteris generic over layer typeLPlotter2D.layershas typeDict[str, Layer2D]Plotter3D.layershas typeDict[str, Layer3D]