You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's important to realize that the status functions accepted both
45
-
tuples/lists of the correct length, and ``NDArray``'s of the correct shape.
46
-
If they only accepted ``NDArray``'s, we would use their ``Internal`` counterparts:
47
-
:class:`~.typing.InternalPoint2D`, :class:`~.typing.InternalPoint3D`, :class:`~.typing.InternalPoint2D_Array` and :class:`~.typing.InternalPoint3D_Array`.
48
-
49
-
In general, the type aliases prefixed with ``Internal`` should never be used on
50
-
user-facing classes and functions, but should be reserved for internal behavior.
41
+
# it's a Point3DLike
42
+
print_point3D(coord)
43
+
44
+
defshift_point_up(coord: Point3DLike) -> Point3D:
45
+
result = np.asarray(coord)
46
+
result +=UP
47
+
return result
48
+
49
+
Notice that the last function, ``shift_point_up()``, accepts a
50
+
:class:`~.Point3DLike` as a parameter and returns a :class:`~.Point3D`. A
51
+
:class:`~.Point3D` always represents a NumPy array consisting of 3 floats,
52
+
whereas a :class:`~.Point3DLike` can represent anything resembling a 3D point:
53
+
either a NumPy array or a tuple/list of 3 floats, hence the ``Like`` word. The
54
+
same happens with :class:`~.Point2D`, :class:`~.Point2D_Array` and
55
+
:class:`~.Point3D_Array`, and their ``Like`` counterparts
56
+
:class:`~.Point2DLike`, :class:`~.Point2DLike_Array` and
57
+
:class:`~.Point3DLike_Array`.
58
+
59
+
The rule for typing functions is: **make parameter types as broad as possible,
60
+
and return types as specific as possible.** Therefore, for functions which are
61
+
intended to be called by users, we should always, if possible, accept ``Like``
62
+
types as parameters and return NumPy, non-``Like`` types. The last function,
63
+
``shift_point_up()``, is an example of it. Internal functions which are *not*
64
+
meant to be called by users may accept non-``Like`` parameters if necessary.
0 commit comments