diff options
author | Hernan Grecco <hgrecco@gmail.com> | 2023-05-04 17:21:35 -0300 |
---|---|---|
committer | Hernan Grecco <hgrecco@gmail.com> | 2023-05-05 03:27:28 -0300 |
commit | 2f4125d0be4caa21a4ce2726bbc266cf265d822d (patch) | |
tree | 01d34e44e1252d953236a56bf1f03b9b4d314202 /pint/facets/formatting/registry.py | |
parent | 5643c32f7f2c886015df459f26b4d72adaee1207 (diff) | |
download | pint-2f4125d0be4caa21a4ce2726bbc266cf265d822d.tar.gz |
Large commit to make Pint more typing friendly
In this very large commit we tackle a few aspects of Pint that
makes it difficult to do static typing.
1. Dynamic classes became static: Quantity and Unit are now
(for the most part) static classes with a static inheritance.
This allows mypy/pylance and other type checker to properly
inspect them.
2. Added types through out all the code. (WIP)
3. Refactor minor parts of the code to make it more typing
homogeneous. Catch a few potential bugs in the way.
4. Add several TODOs that need to be addressed in 0.23
5. Moved some group and system and context code out of the PlainRegistry
6. Moved certain specialized methods out of the PlainRegistry.
Diffstat (limited to 'pint/facets/formatting/registry.py')
-rw-r--r-- | pint/facets/formatting/registry.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/pint/facets/formatting/registry.py b/pint/facets/formatting/registry.py index c4dc373..7684597 100644 --- a/pint/facets/formatting/registry.py +++ b/pint/facets/formatting/registry.py @@ -8,10 +8,21 @@ from __future__ import annotations -from ..plain import PlainRegistry -from .objects import FormattingQuantity, FormattingUnit +from typing import Generic, Any +from ...compat import TypeAlias +from ..plain import GenericPlainRegistry, QuantityT, UnitT +from . import objects -class FormattingRegistry(PlainRegistry): - Quantity = FormattingQuantity - Unit = FormattingUnit + +class GenericFormattingRegistry( + Generic[QuantityT, UnitT], GenericPlainRegistry[QuantityT, UnitT] +): + pass + + +class FormattingRegistry( + GenericFormattingRegistry[objects.FormattingQuantity[Any], objects.FormattingUnit] +): + Quantity: TypeAlias = objects.FormattingQuantity[Any] + Unit: TypeAlias = objects.FormattingUnit |