TypedUnit 0.2.8__tar.gz → 0.2.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. {typedunit-0.2.8 → typedunit-0.2.10}/PKG-INFO +1 -1
  2. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/_version.py +3 -3
  3. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/PKG-INFO +1 -1
  4. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/SOURCES.txt +6 -2
  5. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/scm_file_list.json +6 -2
  6. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/scm_version.json +2 -2
  7. typedunit-0.2.10/docs/images/logo.png +0 -0
  8. typedunit-0.2.10/docs/source/code.rst +20 -0
  9. {typedunit-0.2.8 → typedunit-0.2.10}/docs/source/conf.py +4 -3
  10. typedunit-0.2.10/docs/source/guide/concepts.rst +37 -0
  11. typedunit-0.2.10/docs/source/guide/installation.rst +21 -0
  12. typedunit-0.2.10/docs/source/guide/pint.rst +24 -0
  13. typedunit-0.2.10/docs/source/guide/quickstart.rst +27 -0
  14. typedunit-0.2.10/docs/source/guide/validation.rst +40 -0
  15. typedunit-0.2.10/docs/source/index.rst +39 -0
  16. typedunit-0.2.10/docs/source/references.rst +11 -0
  17. typedunit-0.2.10/docs/source/theory.rst +12 -0
  18. typedunit-0.2.10/docs/source/units.rst +35 -0
  19. typedunit-0.2.8/docs/images/logo.png +0 -0
  20. typedunit-0.2.8/docs/source/_static/favicon.svg +0 -1
  21. typedunit-0.2.8/docs/source/_static/logo.svg +0 -1
  22. typedunit-0.2.8/docs/source/code.rst +0 -7
  23. typedunit-0.2.8/docs/source/index.rst +0 -13
  24. typedunit-0.2.8/docs/source/references.rst +0 -6
  25. typedunit-0.2.8/docs/source/theory.rst +0 -5
  26. {typedunit-0.2.8 → typedunit-0.2.10}/.coveragerc +0 -0
  27. {typedunit-0.2.8 → typedunit-0.2.10}/.flake8 +0 -0
  28. {typedunit-0.2.8 → typedunit-0.2.10}/.github/dependabot.yml +0 -0
  29. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/deploy_PyPi.yml +0 -0
  30. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/deploy_anaconda.yml +0 -0
  31. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/deploy_coverage.yml +0 -0
  32. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/deploy_documentation.yml +0 -0
  33. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/quality.yml +0 -0
  34. {typedunit-0.2.8 → typedunit-0.2.10}/.github/workflows/tests.yml +0 -0
  35. {typedunit-0.2.8 → typedunit-0.2.10}/.gitignore +0 -0
  36. {typedunit-0.2.8 → typedunit-0.2.10}/.pre-commit-config.yaml +0 -0
  37. {typedunit-0.2.8 → typedunit-0.2.10}/CONTRIBUTING.md +0 -0
  38. {typedunit-0.2.8 → typedunit-0.2.10}/LICENSE +0 -0
  39. {typedunit-0.2.8 → typedunit-0.2.10}/Makefile +0 -0
  40. {typedunit-0.2.8 → typedunit-0.2.10}/README.rst +0 -0
  41. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/__init__.py +0 -0
  42. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/directories.py +0 -0
  43. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/helper.py +0 -0
  44. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/units.py +0 -0
  45. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit/utils.py +0 -0
  46. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/dependency_links.txt +0 -0
  47. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/requires.txt +0 -0
  48. {typedunit-0.2.8 → typedunit-0.2.10}/TypedUnit.egg-info/top_level.txt +0 -0
  49. {typedunit-0.2.8 → typedunit-0.2.10}/conda.recipe/meta.yaml +0 -0
  50. {typedunit-0.2.8 → typedunit-0.2.10}/docs/Makefile +0 -0
  51. {typedunit-0.2.8 → typedunit-0.2.10}/docs/examples/README.rst +0 -0
  52. {typedunit-0.2.8 → typedunit-0.2.10}/docs/examples/example_0.py +0 -0
  53. {typedunit-0.2.8 → typedunit-0.2.10}/docs/examples/example_1.py +0 -0
  54. {typedunit-0.2.8 → typedunit-0.2.10}/docs/make.bat +0 -0
  55. {typedunit-0.2.8 → typedunit-0.2.10}/docs/redirect.html +0 -0
  56. {typedunit-0.2.8 → typedunit-0.2.10}/docs/source/_static/default.css +0 -0
  57. {typedunit-0.2.8 → typedunit-0.2.10}/docs/source/_static/layout.css +0 -0
  58. {typedunit-0.2.8 → typedunit-0.2.10}/docs/source/_static/thumbnail.png +0 -0
  59. {typedunit-0.2.8 → typedunit-0.2.10}/docs/source/sg_execution_times.rst +0 -0
  60. {typedunit-0.2.8 → typedunit-0.2.10}/pyproject.toml +0 -0
  61. {typedunit-0.2.8 → typedunit-0.2.10}/pytest.ini +0 -0
  62. {typedunit-0.2.8 → typedunit-0.2.10}/setup.cfg +0 -0
  63. {typedunit-0.2.8 → typedunit-0.2.10}/tests/__init__.py +0 -0
  64. {typedunit-0.2.8 → typedunit-0.2.10}/tests/test_0.py +0 -0
  65. {typedunit-0.2.8 → typedunit-0.2.10}/tools/next_release_version.py +0 -0
  66. {typedunit-0.2.8 → typedunit-0.2.10}/tools/release_tag.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TypedUnit
3
- Version: 0.2.8
3
+ Version: 0.2.10
4
4
  Summary: A package wrapping pint for handling typed units in Python.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.2.8'
22
- __version_tuple__ = version_tuple = (0, 2, 8)
21
+ __version__ = version = '0.2.10'
22
+ __version_tuple__ = version_tuple = (0, 2, 10)
23
23
 
24
- __commit_id__ = commit_id = 'g3316b556e'
24
+ __commit_id__ = commit_id = 'g156c1ff07'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: TypedUnit
3
- Version: 0.2.8
3
+ Version: 0.2.10
4
4
  Summary: A package wrapping pint for handling typed units in Python.
5
5
  Author-email: Martin Poinsinet de Sivry-Houle <martin.poinsinet.de.sivry@gmail.com>
6
6
  License: MIT License
@@ -42,11 +42,15 @@ docs/source/index.rst
42
42
  docs/source/references.rst
43
43
  docs/source/sg_execution_times.rst
44
44
  docs/source/theory.rst
45
+ docs/source/units.rst
45
46
  docs/source/_static/default.css
46
- docs/source/_static/favicon.svg
47
47
  docs/source/_static/layout.css
48
- docs/source/_static/logo.svg
49
48
  docs/source/_static/thumbnail.png
49
+ docs/source/guide/concepts.rst
50
+ docs/source/guide/installation.rst
51
+ docs/source/guide/pint.rst
52
+ docs/source/guide/quickstart.rst
53
+ docs/source/guide/validation.rst
50
54
  tests/__init__.py
51
55
  tests/test_0.py
52
56
  tools/next_release_version.py
@@ -30,16 +30,20 @@
30
30
  "docs/make.bat",
31
31
  "docs/redirect.html",
32
32
  "docs/source/_static/default.css",
33
- "docs/source/_static/favicon.svg",
34
33
  "docs/source/_static/layout.css",
35
- "docs/source/_static/logo.svg",
36
34
  "docs/source/_static/thumbnail.png",
37
35
  "docs/source/code.rst",
38
36
  "docs/source/conf.py",
37
+ "docs/source/guide/concepts.rst",
38
+ "docs/source/guide/installation.rst",
39
+ "docs/source/guide/pint.rst",
40
+ "docs/source/guide/quickstart.rst",
41
+ "docs/source/guide/validation.rst",
39
42
  "docs/source/index.rst",
40
43
  "docs/source/references.rst",
41
44
  "docs/source/sg_execution_times.rst",
42
45
  "docs/source/theory.rst",
46
+ "docs/source/units.rst",
43
47
  "pyproject.toml",
44
48
  "pytest.ini",
45
49
  "tests/__init__.py",
@@ -1,7 +1,7 @@
1
1
  {
2
- "tag": "0.2.8",
2
+ "tag": "0.2.10",
3
3
  "distance": 0,
4
- "node": "g3316b556e08fe9292dd89b9b94223240bc6ff784",
4
+ "node": "g156c1ff077ca68e8002b447cedd677d7dfa3c429",
5
5
  "dirty": true,
6
6
  "branch": "HEAD",
7
7
  "node_date": "2026-10-20"
Binary file
@@ -0,0 +1,20 @@
1
+ .. _source_code:
2
+
3
+ API reference
4
+ =============
5
+
6
+ The reference below is generated from the public modules. See the user guide
7
+ for examples and design explanations.
8
+
9
+ .. automodule:: TypedUnit
10
+ :members:
11
+ :undoc-members:
12
+ :show-inheritance:
13
+
14
+ .. automodule:: TypedUnit.helper
15
+ :members:
16
+ :show-inheritance:
17
+
18
+ .. automodule:: TypedUnit.units
19
+ :members:
20
+ :show-inheritance:
@@ -11,7 +11,8 @@ from martinpdes_docs import configure
11
11
 
12
12
  package_name = "TypedUnit"
13
13
  version = os.getenv("tag", "latest")
14
- thumbnail = str(Path(__file__).parent / "_static" / "thumbnail.png")
14
+ logo = "../images/logo.png"
15
+ thumbnail = str(Path(__file__).parent.parent / "images" / "logo.png")
15
16
 
16
17
  globals().update(
17
18
  configure(
@@ -19,8 +20,8 @@ globals().update(
19
20
  package=package_name,
20
21
  repository="MartinPdeS/TypedUnit",
21
22
  version=version,
22
- logo="_static/logo.svg",
23
- favicon="_static/favicon.svg",
23
+ logo=logo,
24
+ favicon=logo,
24
25
  sphinx_gallery_conf={
25
26
  "default_thumb_file": thumbnail,
26
27
  "within_subsection_order": FileNameSortKey,
@@ -0,0 +1,37 @@
1
+ Core concepts
2
+ =============
3
+
4
+ TypedUnit has three complementary pieces.
5
+
6
+ Dimensional types
7
+ -----------------
8
+
9
+ Classes such as ``Length`` and ``Voltage`` are lightweight marker types. They
10
+ do not wrap or copy a quantity:
11
+
12
+ .. code-block:: python
13
+
14
+ distance = 2 * ureg.kilometer
15
+ isinstance(distance, Length) # True
16
+ isinstance(distance, Mass) # False
17
+
18
+ Pint still owns arithmetic, conversion, formatting, and NumPy integration.
19
+
20
+ The shared registry
21
+ -------------------
22
+
23
+ Import ``ureg`` from TypedUnit rather than constructing a second registry.
24
+ It includes domain units such as ``particle``, ``event``, ``photoelectron``,
25
+ and ``sqrt_hertz``.
26
+
27
+ Derived annotation types
28
+ ------------------------
29
+
30
+ Unit classes can describe derived dimensions:
31
+
32
+ .. code-block:: python
33
+
34
+ EnergyPerTime = Energy / Time
35
+ isinstance(2 * ureg.watt, EnergyPerTime) # True
36
+
37
+ These expressions describe dimensions; use Pint expressions for calculations.
@@ -0,0 +1,21 @@
1
+ Installation
2
+ ============
3
+
4
+ .. code-block:: console
5
+
6
+ $ python -m pip install TypedUnit
7
+
8
+ TypedUnit supports Python 3.10 and newer. Pydantic is optional; install it
9
+ separately when using Pydantic models or dataclasses.
10
+
11
+ For a development checkout:
12
+
13
+ .. code-block:: console
14
+
15
+ $ git clone https://github.com/MartinPdeS/TypedUnit.git
16
+ $ cd TypedUnit
17
+ $ python -m pip install -e ".[testing,documentation]"
18
+ $ pytest
19
+
20
+ The package exposes one application-wide registry, :data:`TypedUnit.ureg`.
21
+ Use it when creating quantities so dimensional checks remain consistent.
@@ -0,0 +1,24 @@
1
+ Working with Pint
2
+ =================
3
+
4
+ TypedUnit is a thin layer over Pint. A quantity remains a normal
5
+ ``pint.Quantity`` and can be converted, indexed, or used with NumPy.
6
+
7
+ .. code-block:: python
8
+
9
+ from TypedUnit import Length, ureg
10
+
11
+ diameter = 30 * ureg.centimeter
12
+ area = (diameter / 2) ** 2 * 3.14159
13
+ assert isinstance(diameter, Length)
14
+ print(area.to(ureg.square_meter))
15
+
16
+ Dimensionality is the source of truth: metres and kilometres are both
17
+ ``Length``. Avoid mixing registries; use the shared ``TypedUnit.ureg`` at
18
+ integration boundaries when external libraries return quantities.
19
+
20
+ TypedUnit classes are markers, not constructors. Create values with Pint:
21
+
22
+ .. code-block:: python
23
+
24
+ energy = 3 * ureg.joule
@@ -0,0 +1,27 @@
1
+ Quick start
2
+ ===========
3
+
4
+ Create quantities as you would with Pint, and use TypedUnit classes where
5
+ physical meaning matters:
6
+
7
+ .. code-block:: python
8
+
9
+ from TypedUnit import Energy, Power, Time, ureg, validate_units
10
+
11
+ energy = 100 * ureg.joule
12
+ duration = 10 * ureg.second
13
+
14
+ assert isinstance(energy, Energy)
15
+ assert isinstance(duration, Time)
16
+
17
+ @validate_units
18
+ def average_power(energy: Energy, duration: Time) -> Power:
19
+ return (energy / duration).to(ureg.watt)
20
+
21
+ print(average_power(energy, duration)) # 10.0 watt
22
+
23
+ Passing ``5 * ureg.meter`` as ``energy`` raises an error before the function
24
+ body runs. Conversion remains explicit: ``energy.to(ureg.kilojoule)``.
25
+
26
+ TypedUnit checks dimensionality, not the display unit. Joules and kilowatt
27
+ hours are both ``Energy``; metres are not.
@@ -0,0 +1,40 @@
1
+ Validating function inputs
2
+ ==========================
3
+
4
+ Decorate a function after adding TypedUnit annotations:
5
+
6
+ .. code-block:: python
7
+
8
+ from TypedUnit import Energy, Time, validate_units, ureg
9
+
10
+ @validate_units
11
+ def energy_rate(energy: Energy, time: Time, label: str = "run"):
12
+ return energy / time, label
13
+
14
+ Only parameters annotated with a TypedUnit class are checked. Ordinary
15
+ annotations such as ``str`` and ``int`` are not runtime-validated, and return
16
+ values are not checked.
17
+
18
+ Optional and collection inputs
19
+ ------------------------------
20
+
21
+ ``Optional`` unit values and homogeneous lists or tuples are supported:
22
+
23
+ .. code-block:: python
24
+
25
+ from typing import Optional
26
+ from TypedUnit import Length, Time, validate_units, ureg
27
+
28
+ @validate_units
29
+ def summarize(points: list[Length], elapsed: Optional[Time] = None):
30
+ return len(points), elapsed
31
+
32
+ Invalid values raise ``ValueError`` with the parameter name and, for a
33
+ collection, its index. A required ``None`` is rejected as well.
34
+
35
+ Pydantic
36
+ --------
37
+
38
+ TypedUnit classes can be used as annotations in Pydantic dataclasses or
39
+ models. Use ``@validate_units`` on calculation functions that accept those
40
+ fields when an explicit function boundary is useful.
@@ -0,0 +1,39 @@
1
+ **Date**: |today|, **Version**: |version|
2
+
3
+
4
+ .. include:: ../../README.rst
5
+ :start-line: 0
6
+
7
+ TypedUnit documentation
8
+ =======================
9
+
10
+ TypedUnit adds readable, runtime-checkable physical quantity types to Pint.
11
+ Keep constructing and converting quantities with Pint, then use types such as
12
+ ``Energy`` in annotations, ``isinstance`` checks, and validated boundaries.
13
+
14
+ .. toctree::
15
+ :maxdepth: 2
16
+ :caption: User guide
17
+
18
+ guide/installation
19
+ guide/quickstart
20
+ guide/concepts
21
+ guide/validation
22
+ guide/pint
23
+ theory
24
+
25
+ .. toctree::
26
+ :maxdepth: 2
27
+ :caption: Reference
28
+
29
+ units
30
+ code
31
+ references
32
+ gallery/index
33
+
34
+ Indices and tables
35
+ ==================
36
+
37
+ * :ref:`genindex`
38
+ * :ref:`modindex`
39
+ * :ref:`search`
@@ -0,0 +1,11 @@
1
+ .. _references:
2
+
3
+ References
4
+ ===========
5
+
6
+ * `Pint documentation <https://pint.readthedocs.io/>`_ — quantities,
7
+ dimensionality, conversion, and registries.
8
+ * `Python typing documentation <https://docs.python.org/3/library/typing.html>`_
9
+ — annotation syntax used by the validator.
10
+ * `Pydantic documentation <https://docs.pydantic.dev/>`_ — model and dataclass
11
+ validation when Pydantic is installed.
@@ -0,0 +1,12 @@
1
+ .. _theory:
2
+
3
+ Theoretical background
4
+ ======================
5
+
6
+ TypedUnit separates values from meaning. Pint stores a magnitude and unit and
7
+ performs dimensional arithmetic. TypedUnit maps selected Pint dimensionalities
8
+ to Python classes, allowing the same meaning to appear in annotations and
9
+ runtime checks without changing the quantity object.
10
+
11
+ For practical usage, start with :doc:`guide/quickstart` and
12
+ :doc:`guide/validation`.
@@ -0,0 +1,35 @@
1
+ Unit types
2
+ ==========
3
+
4
+ All public unit classes are re-exported from ``TypedUnit``.
5
+
6
+ .. list-table:: Common types
7
+ :header-rows: 1
8
+ :widths: 28 36 36
9
+
10
+ * - Type
11
+ - Dimension
12
+ - Typical units
13
+ * - ``Length`` / ``Area`` / ``Volume``
14
+ - length / length squared / volume
15
+ - meter, square_meter, liter
16
+ * - ``Mass`` / ``Time`` / ``Frequency``
17
+ - mass / time / inverse time
18
+ - kilogram, second, hertz
19
+ * - ``Velocity`` / ``FlowRate``
20
+ - length per time / liter per second
21
+ - meter / second, liter / second
22
+ * - ``Energy`` / ``Power``
23
+ - energy / energy per time
24
+ - joule, watt
25
+ * - ``Voltage`` / ``Current`` / ``Resistance``
26
+ - potential / current / resistance
27
+ - volt, ampere, ohm
28
+ * - ``Temperature`` / ``Angle``
29
+ - temperature / angle
30
+ - kelvin, degree
31
+ * - ``Dimensionless`` / ``AnyUnit``
32
+ - no dimensions / any dimensionality
33
+ - dimensionless / any Pint quantity
34
+
35
+ See :doc:`code` for the complete generated class reference.
Binary file
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64"><circle cx="32" cy="32" r="29" fill="#172033"/><rect x="13" y="25" width="24" height="24" rx="5" fill="#6366f1"/><rect x="28" y="15" width="24" height="24" rx="5" fill="#22d3ee" opacity=".9"/></svg>
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 96" role="img" aria-labelledby="t d"><title id="t">TypedUnit</title><desc id="d">Interlocking dimensional unit blocks.</desc><rect x="18" y="25" width="44" height="44" rx="8" fill="#4f46e5"/><rect x="52" y="15" width="44" height="44" rx="8" fill="#06b6d4" opacity=".9"/><path fill="none" stroke="#172033" stroke-width="7" stroke-linecap="round" d="M112 48h27"/><text x="158" y="58" fill="#172033" font-family="system-ui,sans-serif" font-size="30" font-weight="650">TypedUnit</text></svg>
@@ -1,7 +0,0 @@
1
- .. _source_code:
2
-
3
- Source Code
4
- ===========
5
-
6
- This section provides an overview of the primary classes used in the `FiberFusing` package. Each class includes detailed descriptions of its members and inherited members, organized by their source order for easy reference.
7
-
@@ -1,13 +0,0 @@
1
- **Date**: |today|, **Version**: |version|
2
-
3
-
4
- .. include:: ../../README.rst
5
- :start-line: 0
6
-
7
- .. toctree::
8
- :hidden:
9
-
10
- theory
11
- code
12
- gallery/index
13
- references
@@ -1,6 +0,0 @@
1
- .. _references:
2
-
3
- References
4
- ===========
5
-
6
-
@@ -1,5 +0,0 @@
1
- .. _theory:
2
-
3
- Theoretical background
4
- ======================
5
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes