From 44c85974b896b555538e2189d5fffaeebb0b291f Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Wed, 17 Aug 2022 12:52:23 +1000 Subject: [PATCH 1/2] Add __all__ to exceptions module --- openff/units/exceptions.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/openff/units/exceptions.py b/openff/units/exceptions.py index 5b2bfe4..9183e81 100644 --- a/openff/units/exceptions.py +++ b/openff/units/exceptions.py @@ -1,3 +1,10 @@ +__all__ = [ + "MissingOpenMMUnitError", + "NoneQuantityError", + "NoneUnitError", +] + + class MissingOpenMMUnitError(Exception): """Raised when a unit cannot be converted to an equivalent OpenMM unit""" From 6608ec356af7ced9ca0909e41600380169bef1de Mon Sep 17 00:00:00 2001 From: Josh Mitchell Date: Wed, 17 Aug 2022 12:53:43 +1000 Subject: [PATCH 2/2] Preserve generic type hints from Pint. Inheriting from a generic type without specifying the generic fixes the generic to `Any`. This breaks strict type checking and prevents users from specifying the type that a Quantity is wrapping. --- openff/units/units.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/openff/units/units.py b/openff/units/units.py index 332425f..30cabfa 100644 --- a/openff/units/units.py +++ b/openff/units/units.py @@ -4,7 +4,7 @@ import uuid import warnings -from typing import TYPE_CHECKING +from typing import TYPE_CHECKING, TypeVar import pint from openff.utilities import requires_package @@ -52,7 +52,10 @@ def __reduce__(self): return _unpickle_unit, (Unit, self._units) -class Quantity(_Quantity): +_MagnitudeType = TypeVar("_MagnitudeType") + + +class Quantity(_Quantity[_MagnitudeType]): """A value with associated units.""" _REGISTRY = DEFAULT_UNIT_REGISTRY