Refactor the code to make it compliant with Python 3 typing
nicolargo opened this issue · 5 comments
Glances has been developed for Python 2. The next version (4.0.0) will only be compliant with Python 3.8 or higher.
It's time to refactor the code to provides runtime support for type hints: https://docs.python.org/3/library/typing.html
@RazCrimson any experiences/tips to convert a Python code for Python 3 typing ? Do you think that we must include an external type checker (like mypi or others) ?
Some resources found on the net:
@RazCrimson any experiences/tips to convert a Python code for Python 3 typing ? Do you think that we must include an external type checker (like mypi or others)
Yes, mypy would be nice to add it
For glances but since most of the our variables are dicts, typing them directly would not be really useful.
We should start typing after we define the models (pydantic issue mentioned above), otherwise we would have the change the types of all those dicts into their corresponding pydantic equivalents later which would be extra work.
Hi @RazCrimson on the https://github.com/nicolargo/glances/tree/2404-refactor-the-code-to-make-it-compliant-with-python-3-typing branch, i start the refactoring by creating two news dataclasses: GlancesDataItem and GlancesDataPlugin.
Those classes are for the moment only used in the CPU and MEM plugins and simplify the plugins code.
Can you have a first look and tell me if you see others thinks to improve and will simplify the API documentation.
For the moment, typing is limited to the new dataclasses and there is no verification (non pydantic for the moment).
Sure, will take a look at them over the weekend!
Additional question: How to deal with plugin returning list of dict ?
In this case, how to define the plugin with fields_description ?
The data model (after export) could:
- be the same than Glances version 3: a list of dict <== better choice, i think
- change: a dict of dict