Skip to content

Commit

Permalink
Docs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
leroyvn committed Jan 27, 2021
1 parent 4d97047 commit 161e786
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion docs/rst/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Default unit registry
Dictionary interpretation
-------------------------

.. autofundction:: pinttr.interpret_units
.. autofunction:: pinttr.interpret_units

Converters [``pinttr.converters``]
----------------------------------
Expand Down
16 changes: 8 additions & 8 deletions docs/rst/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ is the main difference and allows for the attachment of units to a field:

Scalar values are automatically wrapped in Pint units. If a Pint quantity is
passed as an attribute value, its units will be checked. If they prove to be
compatible in the sense of Pinttrs, the value will be assigned to the attribute
:ref:`compatible in the sense of Pinttrs <compatible>`, the value will be assigned to the attribute
without modification:

.. doctest::
Expand Down Expand Up @@ -104,15 +104,10 @@ Callables can be used to vary default units dynamically at runtime:
>>> MyClass(1.0)
MyClass(field=<Quantity(1.0, 'second')>)

Default units with contextual overrides
---------------------------------------

Coming soon.

Dict-based object initialisation with units
-------------------------------------------

Pinttrs ships a helper function :func:`pinttrinterpret_units` which can be
Pinttrs ships a helper function :func:`pinttr.interpret_units` which can be
used to interpret units in a dictionary with string-valued keys:

.. doctest::
Expand Down Expand Up @@ -143,4 +138,9 @@ Example:
.. note::

The same unit registry must be used to define field units and interpret
dictionaries.
dictionaries.

Default units with contextual override
--------------------------------------

Coming soon.
2 changes: 1 addition & 1 deletion src/pinttr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from ._make import attrib

# Package metadata
__version__ = "0.1.0-dev1"
__version__ = "0.1.0-dev2"
__copyright__ = "Copyright (c) 2021 Vincent Leroy"

# Other definitions
Expand Down
9 changes: 9 additions & 0 deletions src/pinttr/_defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
def set_unit_registry(ureg):
"""
Set unit registry. By default, Pinttrs has its own registry.
:param ureg:
Unit registry.
:type ureg:
:class:`pint.UnitRegistry`
:raises:
:class:`TypeError` if ``ureg`` is not a :class:`pint.UnitRegistry`.
"""
global unit_registry
if not isinstance(ureg, pint.UnitRegistry):
Expand Down
4 changes: 2 additions & 2 deletions src/pinttr/_interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def interpret_units(d, ureg=None, inplace=False):
.. warning::
* Dictionary keys must be strings.
Dictionary keys must be strings.
:param d:
Dictionary in which units will be interpreted.
Expand All @@ -42,7 +42,7 @@ def interpret_units(d, ureg=None, inplace=False):
:func:`pinttr.set_unit_registry`.
:type ureg:
:class:`pint.UnitRegistry`
:class:`pint.UnitRegistry` or ``None``
:param inplace:
If ``True``, modify the dictionary in-place; otherwise, return a
Expand Down

0 comments on commit 161e786

Please sign in to comment.