|
24 | 24 |
|
25 | 25 |
|
26 | 26 | class Quantity: |
27 | | - """A quantity with a unit.""" |
| 27 | + """A quantity with a unit. |
| 28 | +
|
| 29 | + Quantities try to behave like float and are also immutable. |
| 30 | + """ |
28 | 31 |
|
29 | 32 | _base_value: float |
30 | 33 | """The value of this quantity in the base unit.""" |
@@ -249,48 +252,6 @@ def __mul__(self, percent: Percentage) -> Self: |
249 | 252 | product._base_value = self._base_value * percent.as_fraction() |
250 | 253 | return product |
251 | 254 |
|
252 | | - def __iadd__(self, other: Self) -> Self: |
253 | | - """Add another quantity to this one. |
254 | | -
|
255 | | - Args: |
256 | | - other: The other quantity. |
257 | | -
|
258 | | - Returns: |
259 | | - This quantity. |
260 | | - """ |
261 | | - if not type(other) is type(self): |
262 | | - return NotImplemented |
263 | | - self._base_value += other._base_value |
264 | | - return self |
265 | | - |
266 | | - def __isub__(self, other: Self) -> Self: |
267 | | - """Subtract another quantity from this one. |
268 | | -
|
269 | | - Args: |
270 | | - other: The other quantity. |
271 | | -
|
272 | | - Returns: |
273 | | - This quantity. |
274 | | - """ |
275 | | - if not type(other) is type(self): |
276 | | - return NotImplemented |
277 | | - self._base_value -= other._base_value |
278 | | - return self |
279 | | - |
280 | | - def __imul__(self, percent: Percentage) -> Self: |
281 | | - """Multiply this quantity by a percentage. |
282 | | -
|
283 | | - Args: |
284 | | - percent: The percentage. |
285 | | -
|
286 | | - Returns: |
287 | | - This quantity. |
288 | | - """ |
289 | | - if not isinstance(percent, Percentage): |
290 | | - return NotImplemented |
291 | | - self._base_value *= percent.as_fraction() |
292 | | - return self |
293 | | - |
294 | 255 | def __gt__(self, other: Self) -> bool: |
295 | 256 | """Return whether this quantity is greater than another. |
296 | 257 |
|
@@ -413,7 +374,7 @@ class Power( |
413 | 374 | ): |
414 | 375 | """A power quantity. |
415 | 376 |
|
416 | | - Objects of this type are wrappers around `float` values. |
| 377 | + Objects of this type are wrappers around `float` values and are immutable. |
417 | 378 |
|
418 | 379 | The constructors accept a single `float` value, the `as_*()` methods return a |
419 | 380 | `float` value, and each of the arithmetic operators supported by this type are |
@@ -586,7 +547,7 @@ class Current( |
586 | 547 | ): |
587 | 548 | """A current quantity. |
588 | 549 |
|
589 | | - Objects of this type are wrappers around `float` values. |
| 550 | + Objects of this type are wrappers around `float` values and are immutable. |
590 | 551 |
|
591 | 552 | The constructors accept a single `float` value, the `as_*()` methods return a |
592 | 553 | `float` value, and each of the arithmetic operators supported by this type are |
@@ -682,7 +643,7 @@ class Voltage( |
682 | 643 | ): |
683 | 644 | """A voltage quantity. |
684 | 645 |
|
685 | | - Objects of this type are wrappers around `float` values. |
| 646 | + Objects of this type are wrappers around `float` values and are immutable. |
686 | 647 |
|
687 | 648 | The constructors accept a single `float` value, the `as_*()` methods return a |
688 | 649 | `float` value, and each of the arithmetic operators supported by this type are |
@@ -804,7 +765,7 @@ class Energy( |
804 | 765 | ): |
805 | 766 | """An energy quantity. |
806 | 767 |
|
807 | | - Objects of this type are wrappers around `float` values. |
| 768 | + Objects of this type are wrappers around `float` values and are immutable. |
808 | 769 |
|
809 | 770 | The constructors accept a single `float` value, the `as_*()` methods return a |
810 | 771 | `float` value, and each of the arithmetic operators supported by this type are |
@@ -923,7 +884,7 @@ class Frequency( |
923 | 884 | ): |
924 | 885 | """A frequency quantity. |
925 | 886 |
|
926 | | - Objects of this type are wrappers around `float` values. |
| 887 | + Objects of this type are wrappers around `float` values and are immutable. |
927 | 888 |
|
928 | 889 | The constructors accept a single `float` value, the `as_*()` methods return a |
929 | 890 | `float` value, and each of the arithmetic operators supported by this type are |
@@ -1036,7 +997,7 @@ class Percentage( |
1036 | 997 | ): |
1037 | 998 | """A percentage quantity. |
1038 | 999 |
|
1039 | | - Objects of this type are wrappers around `float` values. |
| 1000 | + Objects of this type are wrappers around `float` values and are immutable. |
1040 | 1001 |
|
1041 | 1002 | The constructors accept a single `float` value, the `as_*()` methods return a |
1042 | 1003 | `float` value, and each of the arithmetic operators supported by this type are |
|
0 commit comments