Skip to content

Commit a50e5d6

Browse files
committed
docs
1 parent 7ecfe3c commit a50e5d6

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

docs/advanced/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Pint contains some useful and fun feature. You will find them here.
1010
performance
1111
serialization
1212
defining
13+
typing
1314
wrapping
1415
measurement
1516
pitheorem

docs/advanced/wrapping.rst

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
.. _wrapping:
22

3-
Wrapping and checking functions
4-
===============================
3+
Wrapping, checking functions and type annotations
4+
=================================================
55

66
In some cases you might want to use pint with a pre-existing web service or library
77
which is not units aware. Or you might want to write a fast implementation of a
@@ -260,3 +260,20 @@ If you just want to check the dimensionality of a quantity, you can do so with t
260260
True
261261
>>> distance.check('[time]')
262262
False
263+
264+
265+
Checking dimensionality
266+
-----------------------
267+
268+
Pint's Quantity class supports type annotations, which can be used to specify the type of
269+
the magnitude (e.g., float, int, np.ndarray)
270+
271+
272+
.. doctest::
273+
274+
>>> import numpy as np
275+
>>> import pint
276+
>>> def my_scalar_func(x: pint.Quantity[float]) -> pint.Quantity[float]:
277+
... pass
278+
>>> def my_array_func(x: pint.Quantity[np.ndarray[(3, ), int]]) -> pint.Quantity[np.ndarray[(3, ), int]]:
279+
... pass

0 commit comments

Comments
 (0)