Skip to content

Commit

Permalink
Drop pint type-hinting until it is properly supported
Browse files Browse the repository at this point in the history
hgrecco/pint#1166
Signed-off-by: Cristian Le <[email protected]>
  • Loading branch information
LecrisUT committed Apr 2, 2024
1 parent e04446a commit 9b73d02
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion tmt/hardware.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@
from tmt.utils import SpecBasedContainer

if TYPE_CHECKING:
import importlib.metadata

from packaging import version
from pint import Quantity

# Using TypeAlias and typing-extensions under the guard of TYPE_CHECKING,
Expand All @@ -64,7 +67,14 @@
from typing_extensions import TypeAlias

#: A type of values describing sizes of things like storage or RAM.
Size: TypeAlias = 'Quantity[int]'
if version.parse(importlib.metadata.version("pint")) >= version.parse("0.20"):
# Note, type-hinting is not properly supported in pint
# https://github.com/hgrecco/pint/issues/1166
Size: TypeAlias = Quantity
else:
# But this one used to work < 0.20 ¯\_(ツ)_/¯
# https://github.com/hgrecco/pint/pull/1259
Size: TypeAlias = 'Quantity[int]'

#: Unit registry, used and shared by all code.
UNITS = pint.UnitRegistry()
Expand Down

0 comments on commit 9b73d02

Please sign in to comment.