pymodbus-dev / pymodbus

A full modbus protocol written in python
Other
2.25k stars 921 forks source link

Improve simulator type hints #2084

Closed alexrudd2 closed 7 months ago

alexrudd2 commented 7 months ago

Solves another 3 mypy errors.

config_types below seemed like a good candidate for using a TypedDict (~equivalent to a struct) https://github.com/pymodbus-dev/pymodbus/blob/214c7ed4ef27c686ad5d161b78477cc5aa6cb1cc/pymodbus/datastore/simulator.py#L110-L117

However, I ran into issues: (1) mypy doesn't support using variables as TypedDict keys: https://github.com/python/mypy/issues/7178. This unfortunate deficiency means TypedDict is not suitable here until mypy improves. (2) Using type as a key is messy, since it's a "soft keyword". Maybe it would be better to use kind? This should have a benefit beyond mypy.