summaryrefslogtreecommitdiff
path: root/pint/compat.py
diff options
context:
space:
mode:
authorHernan Grecco <hgrecco@gmail.com>2023-05-04 17:21:35 -0300
committerHernan Grecco <hgrecco@gmail.com>2023-05-05 03:27:28 -0300
commit2f4125d0be4caa21a4ce2726bbc266cf265d822d (patch)
tree01d34e44e1252d953236a56bf1f03b9b4d314202 /pint/compat.py
parent5643c32f7f2c886015df459f26b4d72adaee1207 (diff)
downloadpint-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/compat.py')
-rw-r--r--pint/compat.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/pint/compat.py b/pint/compat.py
index 7b48efa..727ff99 100644
--- a/pint/compat.py
+++ b/pint/compat.py
@@ -20,6 +20,16 @@ from collections.abc import Mapping
from typing import Any, NoReturn, Callable
from collections.abc import Generator, Iterable
+try:
+ from typing import TypeAlias # noqa
+except ImportError:
+ from typing_extensions import TypeAlias # noqa
+
+try:
+ from typing import Self # noqa
+except ImportError:
+ from typing_extensions import Self # noqa
+
def missing_dependency(
package: str, display_name: str | None = None
@@ -137,10 +147,10 @@ except ImportError:
HAS_UNCERTAINTIES = False
try:
- from babel import Locale as Loc
+ from babel import Locale
from babel import units as babel_units
- babel_parse = Loc.parse
+ babel_parse = Locale.parse
HAS_BABEL = hasattr(babel_units, "format_unit")
except ImportError: