|
53 | 53 | }, |
54 | 54 | { |
55 | 55 | "cell_type": "code", |
56 | | - "execution_count": null, |
| 56 | + "execution_count": 2, |
57 | 57 | "metadata": {}, |
58 | 58 | "outputs": [], |
59 | 59 | "source": [ |
|
62 | 62 | "def matrix_add(\n", |
63 | 63 | " input: ArrayLike[float]\n", |
64 | 64 | ") -> ArrayLike[float]:\n", |
65 | | - " \n", |
| 65 | + " \"\"\"Function docsting.\"\"\"\n", |
66 | 66 | " return input + input" |
67 | 67 | ] |
68 | 68 | }, |
69 | 69 | { |
70 | 70 | "cell_type": "markdown", |
71 | 71 | "metadata": {}, |
72 | 72 | "source": [ |
73 | | - "And in the context of DeepTrack2, a larger class with several type hints can look something like the following:\n", |
74 | | - "```python\n", |
75 | | - "class Augmentation(Feature):\n", |
| 73 | + "And in the context of DeepTrack2, a larger class with several type hints can look something like the following:" |
| 74 | + ] |
| 75 | + }, |
| 76 | + { |
| 77 | + "cell_type": "code", |
| 78 | + "execution_count": 3, |
| 79 | + "metadata": {}, |
| 80 | + "outputs": [], |
| 81 | + "source": [ |
| 82 | + "from __future__ import annotations\n", |
| 83 | + "import deeptrack as dt\n", |
| 84 | + "from deeptrack.types import PropertyLike\n", |
| 85 | + "\n", |
| 86 | + "class Augmentation(dt.Feature):\n", |
| 87 | + "\n", |
76 | 88 | " def __init__(\n", |
77 | | - " self,\n", |
| 89 | + " self: Augmentation,\n", |
78 | 90 | " time_consistent: bool = False,\n", |
79 | 91 | " **kwargs\n", |
80 | 92 | " ) -> None:\n", |
81 | 93 | " super().__init__(time_consistent=time_consistent, **kwargs)\n", |
82 | 94 | "\n", |
83 | | - " def _image_wrapped_process_and_get (\n", |
84 | | - " self,\n", |
85 | | - " image_list: List[Image],\n", |
| 95 | + " def _image_wrapped_process_and_get(\n", |
| 96 | + " self: Augmentation,\n", |
| 97 | + " image_list: list[Image],\n", |
86 | 98 | " time_consistent: PropertyLike[bool],\n", |
87 | 99 | " **kwargs\n", |
88 | | - " ) -> List[List]:\n", |
89 | | - "\n", |
90 | | - "```" |
| 100 | + " ) -> list[Image]:\n", |
| 101 | + " pass" |
91 | 102 | ] |
92 | 103 | }, |
93 | 104 | { |
|
99 | 110 | "We will now declare a new type hint of our own which will represent non-integer numeric datatypes with higher precision than the standard float datatype. We will use `Union` for this, which lets us gather datatypes into a single set." |
100 | 111 | ] |
101 | 112 | }, |
| 113 | + { |
| 114 | + "cell_type": "markdown", |
| 115 | + "metadata": {}, |
| 116 | + "source": [ |
| 117 | + "Declare the new type using Union ..." |
| 118 | + ] |
| 119 | + }, |
102 | 120 | { |
103 | 121 | "cell_type": "code", |
104 | | - "execution_count": null, |
| 122 | + "execution_count": 4, |
105 | 123 | "metadata": {}, |
106 | | - "outputs": [], |
| 124 | + "outputs": [ |
| 125 | + { |
| 126 | + "name": "stdout", |
| 127 | + "output_type": "stream", |
| 128 | + "text": [ |
| 129 | + "typing.Union[numpy.float64, numpy.longdouble, numpy.clongdouble]\n" |
| 130 | + ] |
| 131 | + } |
| 132 | + ], |
107 | 133 | "source": [ |
108 | | - "from typing import Union\n", |
109 | 134 | "import numpy as np\n", |
| 135 | + "from typing import Union\n", |
110 | 136 | "\n", |
111 | | - "# Declare type with Union.\n", |
112 | 137 | "DoubleLike = Union[np.float64, np.longdouble, np.longcomplex]\n", |
113 | | - "print(DoubleLike)\n", |
114 | | - "\n", |
115 | | - "# Declare function with new type hint.\n", |
| 138 | + "print(DoubleLike)" |
| 139 | + ] |
| 140 | + }, |
| 141 | + { |
| 142 | + "cell_type": "markdown", |
| 143 | + "metadata": {}, |
| 144 | + "source": [ |
| 145 | + "... and declare function with new type hint." |
| 146 | + ] |
| 147 | + }, |
| 148 | + { |
| 149 | + "cell_type": "code", |
| 150 | + "execution_count": 5, |
| 151 | + "metadata": {}, |
| 152 | + "outputs": [], |
| 153 | + "source": [ |
116 | 154 | "def double_add(\n", |
117 | 155 | " input: ArrayLike[DoubleLike],\n", |
118 | 156 | " number: DoubleLike\n", |
119 | 157 | ") -> ArrayLike[DoubleLike]:\n", |
120 | | - " \n", |
121 | | - " return input + number\n", |
122 | | - "\n" |
| 158 | + " \"\"\"Function docsting.\"\"\"\n", |
| 159 | + " return input + number" |
123 | 160 | ] |
124 | 161 | } |
125 | 162 | ], |
126 | 163 | "metadata": { |
127 | 164 | "kernelspec": { |
128 | | - "display_name": "Python 3", |
| 165 | + "display_name": "py_env_book", |
129 | 166 | "language": "python", |
130 | 167 | "name": "python3" |
131 | 168 | }, |
|
139 | 176 | "name": "python", |
140 | 177 | "nbconvert_exporter": "python", |
141 | 178 | "pygments_lexer": "ipython3", |
142 | | - "version": "3.9.13" |
| 179 | + "version": "3.10.15" |
143 | 180 | } |
144 | 181 | }, |
145 | 182 | "nbformat": 4, |
|
0 commit comments