Skip to content

Commit

Permalink
Use formatter delegate in plain facet (will not be used while the For…
Browse files Browse the repository at this point in the history
…matting facet is in place)
  • Loading branch information
hgrecco committed Nov 3, 2023
1 parent 05d4778 commit d0cf14f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pint/facets/plain/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def __deepcopy__(self, memo) -> PlainQuantity[MagnitudeT]:
return ret

def __str__(self) -> str:
return str(self.magnitude) + " " + str(self.units)
return self._REGISTRY.formatter.format_quantity(self)

def __bytes__(self) -> bytes:
return str(self).encode(locale.getpreferredencoding())
Expand Down
5 changes: 5 additions & 0 deletions pint/facets/plain/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
if TYPE_CHECKING:
from ..context import Context
from ...compat import Locale
from ... import protocols

# from ..._typing import Quantity, Unit

Expand Down Expand Up @@ -215,6 +216,8 @@ class GenericPlainRegistry(Generic[QuantityT, UnitT], metaclass=RegistryMeta):
_diskcache = None
_def_parser = None

formatter: protocols.Formatter

def __init__(
self,
filename="",
Expand Down Expand Up @@ -251,6 +254,8 @@ def __init__(
delegates.ParserConfig(non_int_type), diskcache=self._diskcache
)

self.formatter = delegates.Formatter()

self._filename = filename
self.force_ndarray = force_ndarray
self.force_ndarray_like = force_ndarray_like
Expand Down
2 changes: 1 addition & 1 deletion pint/facets/plain/unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __deepcopy__(self, memo) -> PlainUnit:
return ret

def __str__(self) -> str:
return " ".join(k if v == 1 else f"{k} ** {v}" for k, v in self._units.items())
return self._REGISTRY.formatter.format_unit(self)

def __bytes__(self) -> bytes:
return str(self).encode(locale.getpreferredencoding())
Expand Down

0 comments on commit d0cf14f

Please sign in to comment.