This is a discussion related to typing, #358.
canopen use Mapping and MutableMapping for 10 classes. Due to limitations in Python 3.8, they cannot be annotated and the following will not work
class Network(MutableMapping[int, Union[RemoteNode, LocalNode]]):
Python 3.8 gives the error: TypeError: 'ABCMeta' object is not subscriptable. The effect is that a code base supporting 3.8 cannot use type hints on Mapping. These classes are very central to the function of canopen, so I think we'd miss out on significant type annotation aids if we don't get to use it.
There are a few options available to us:
- Bump the minimum Python version to 3.9
- Don't use type annotations on any of the
Mapping and MutableMapping classes because we need Python 3.8 compatibility
- Use a run-time hack that conditionally adds the type annotations. Below example is inspired from this example
- Some way to annotate these classes that works with >=3.8 that I don't know about
# Example to annotate MutableMapping that makes it run on Python 3.8
import sys
if sys.version_info >= (3, 9):
TMutableMapping = MutableMapping[int, Union[RemoteNode, LocalNode]]
else:
TMutableMapping = MutableMapping
class Network(TMutableMapping):
"""Representation of one CAN bus containing one or more nodes."""
This is a discussion related to typing, #358.
canopen use
MappingandMutableMappingfor 10 classes. Due to limitations in Python 3.8, they cannot be annotated and the following will not workPython 3.8 gives the error:
TypeError: 'ABCMeta' object is not subscriptable. The effect is that a code base supporting 3.8 cannot use type hints onMapping. These classes are very central to the function of canopen, so I think we'd miss out on significant type annotation aids if we don't get to use it.There are a few options available to us:
MappingandMutableMappingclasses because we need Python 3.8 compatibility