Skip to content

Commit

Permalink
Moved preprecessors from parse_units to _parse_units
Browse files Browse the repository at this point in the history
  • Loading branch information
hgrecco committed Jul 15, 2023
1 parent dbb12a7 commit 10ef992
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
:copyright: 2022 by Pint Authors, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
The registry contains the following important methods:
- parse_units: Parse a units expression and returns a UnitContainer with
the canonical names.
The expression can only contain products, ratios and powers of units;
prefixed units and pluralized units.
-
"""

from __future__ import annotations
Expand Down Expand Up @@ -349,6 +358,8 @@ def __deepcopy__(self: Self, memo) -> type[Self]:

def __getattr__(self, item: str) -> QuantityT:
getattr_maybe_raise(self, item)

# self.Unit will call parse_units
return self.Unit(item)

def __getitem__(self, item: str) -> UnitT:
Expand Down Expand Up @@ -1127,9 +1138,6 @@ def parse_units(
"""

# TODO: deal or remove with as_delta = None
for p in self.preprocessors:
input_string = p(input_string)
units = self._parse_units(input_string, as_delta, case_sensitive)
return self.Unit(units)

Expand All @@ -1150,6 +1158,9 @@ def _parse_units(
if as_delta and input_string in cache and input_string in self._units:
return cache[input_string]

for p in self.preprocessors:
input_string = p(input_string)

if not input_string:
return self.UnitsContainer()

Expand Down

0 comments on commit 10ef992

Please sign in to comment.