From d61f7fc55d31b4c92bb50429bcee5d2f713f0bf2 Mon Sep 17 00:00:00 2001 From: Mike O'Connor Date: Mon, 26 Jun 2023 23:06:59 +0100 Subject: [PATCH] Fix Transformation type protocol Adding ureg to the argument list for Transformation Protocol Closes #1801 --- CHANGES | 2 ++ pint/facets/context/objects.py | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 597000896..278b8ce41 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,8 @@ Pint Changelog 0.23 (unreleased) ----------------- +- Fixed Transformation type protocol. + (PR #1805) - Documented to_preferred and created added an autoautoconvert_to_preferred registry option. (PR #1803) diff --git a/pint/facets/context/objects.py b/pint/facets/context/objects.py index 4ab2f1d52..9001e9666 100644 --- a/pint/facets/context/objects.py +++ b/pint/facets/context/objects.py @@ -10,7 +10,7 @@ import weakref from collections import ChainMap, defaultdict -from typing import Any, Callable, Protocol, Generic, Optional +from typing import Any, Callable, Protocol, Generic, Optional, TYPE_CHECKING from collections.abc import Iterable from ...facets.plain import UnitDefinition, PlainQuantity, PlainUnit, MagnitudeT @@ -18,9 +18,14 @@ from .definitions import ContextDefinition from ..._typing import Magnitude +if TYPE_CHECKING: + from ...registry import UnitRegistry + class Transformation(Protocol): - def __call__(self, value: Magnitude, **kwargs: Any) -> Magnitude: + def __call__( + self, ureg: UnitRegistry, value: Magnitude, **kwargs: Any + ) -> Magnitude: ...