u 3.0__tar.gz → 4.0__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 (53) hide show
  1. {u-3.0 → u-4.0}/PKG-INFO +1 -1
  2. {u-3.0 → u-4.0}/changelog.md +11 -0
  3. {u-3.0 → u-4.0}/tests/test_quantities.py +5 -0
  4. {u-3.0 → u-4.0}/u/__init__.py +1 -1
  5. {u-3.0 → u-4.0}/u/quantity.py +8 -5
  6. {u-3.0 → u-4.0}/.gitignore +0 -0
  7. {u-3.0 → u-4.0}/LICENSE.txt +0 -0
  8. {u-3.0 → u-4.0}/README.md +0 -0
  9. {u-3.0 → u-4.0}/docs/api/quantity.md +0 -0
  10. {u-3.0 → u-4.0}/docs/api/unit.md +0 -0
  11. {u-3.0 → u-4.0}/docs/index.md +0 -0
  12. {u-3.0 → u-4.0}/mkdocs.yml +0 -0
  13. {u-3.0 → u-4.0}/pyproject.toml +0 -0
  14. {u-3.0 → u-4.0}/tests/static_tests.py +0 -0
  15. {u-3.0 → u-4.0}/tests/test_conversions.py +0 -0
  16. {u-3.0 → u-4.0}/tests/test_decimal.py +0 -0
  17. {u-3.0 → u-4.0}/tests/test_math.py +0 -0
  18. {u-3.0 → u-4.0}/tests/test_prefixes.py +0 -0
  19. {u-3.0 → u-4.0}/tests/test_typing.py +0 -0
  20. {u-3.0 → u-4.0}/tests/test_units.py +0 -0
  21. {u-3.0 → u-4.0}/u/_utils.py +0 -0
  22. {u-3.0 → u-4.0}/u/capital_quantities.py +0 -0
  23. {u-3.0 → u-4.0}/u/cli/__init__.py +0 -0
  24. {u-3.0 → u-4.0}/u/cli/make_derived_quantity.py +0 -0
  25. {u-3.0 → u-4.0}/u/maths.py +0 -0
  26. {u-3.0 → u-4.0}/u/prefixes.py +0 -0
  27. {u-3.0 → u-4.0}/u/quantities/__init__.py +0 -0
  28. {u-3.0 → u-4.0}/u/quantities/acceleration.py +0 -0
  29. {u-3.0 → u-4.0}/u/quantities/amount_of_substance.py +0 -0
  30. {u-3.0 → u-4.0}/u/quantities/angle.py +0 -0
  31. {u-3.0 → u-4.0}/u/quantities/area.py +0 -0
  32. {u-3.0 → u-4.0}/u/quantities/data_transfer_speed.py +0 -0
  33. {u-3.0 → u-4.0}/u/quantities/data_volume.py +0 -0
  34. {u-3.0 → u-4.0}/u/quantities/distance.py +0 -0
  35. {u-3.0 → u-4.0}/u/quantities/duration.py +0 -0
  36. {u-3.0 → u-4.0}/u/quantities/electric_charge.py +0 -0
  37. {u-3.0 → u-4.0}/u/quantities/electric_current.py +0 -0
  38. {u-3.0 → u-4.0}/u/quantities/electric_resistance.py +0 -0
  39. {u-3.0 → u-4.0}/u/quantities/energy.py +0 -0
  40. {u-3.0 → u-4.0}/u/quantities/force.py +0 -0
  41. {u-3.0 → u-4.0}/u/quantities/frequency.py +0 -0
  42. {u-3.0 → u-4.0}/u/quantities/luminous_intensity.py +0 -0
  43. {u-3.0 → u-4.0}/u/quantities/mass.py +0 -0
  44. {u-3.0 → u-4.0}/u/quantities/one.py +0 -0
  45. {u-3.0 → u-4.0}/u/quantities/pixels.py +0 -0
  46. {u-3.0 → u-4.0}/u/quantities/power.py +0 -0
  47. {u-3.0 → u-4.0}/u/quantities/pressure.py +0 -0
  48. {u-3.0 → u-4.0}/u/quantities/solid_angle.py +0 -0
  49. {u-3.0 → u-4.0}/u/quantities/speed.py +0 -0
  50. {u-3.0 → u-4.0}/u/quantities/temperature.py +0 -0
  51. {u-3.0 → u-4.0}/u/quantities/volume.py +0 -0
  52. {u-3.0 → u-4.0}/u/unit.py +0 -0
  53. {u-3.0 → u-4.0}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: u
3
- Version: 3.0
3
+ Version: 4.0
4
4
  Summary: Statically typed units
5
5
  Keywords: units,dimensions
6
6
  Author-email: Aran-Fey <rawing7@gmail.com>
@@ -1,9 +1,20 @@
1
+ # 4.0
2
+
3
+ - Comparison operators in `Quantity` no longer use `math.isclose`, and hashing no longer rounds.
4
+ Basically, comparing `Quantity` objects is now just as unpredictable as comparing floats. The
5
+ upside is that equality is now transitive. (i.e. if `a == b` and `b == c`, then `a == c`.)
6
+
7
+ # 3.1
8
+
9
+ - Add `__hash__` method
10
+
1
11
  # 3.0
2
12
 
3
13
  - Add support for `decimal.Decimal`. Unlike floats and Decimals, which throw a TypeError when used
4
14
  together, `Quantity`s remain interoperable regardless of whether they were created with a float or
5
15
  a Decimal.
6
16
  - `Unit.multiplier` is now a Decimal.
17
+ - Add `systems` parameter and attribute to `Unit`
7
18
 
8
19
  # 2.1
9
20
 
@@ -8,3 +8,8 @@ def test_getitem():
8
8
 
9
9
  def test_equality():
10
10
  assert u.minutes(60) == u.hours(1)
11
+
12
+
13
+ def test_hashing():
14
+ mapping = {u.minutes(60): "foo"}
15
+ assert mapping[u.hours(1)] == "foo"
@@ -1,4 +1,4 @@
1
- __version__ = "3.0"
1
+ __version__ = "4.0"
2
2
 
3
3
  from .prefixes import *
4
4
  from .quantity import *
@@ -417,6 +417,9 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
417
417
  def __neg__(self) -> Quantity[Q_co]:
418
418
  return Quantity(-self._value, self._unit)
419
419
 
420
+ def __hash__(self) -> int:
421
+ return hash((self._value, self._unit))
422
+
420
423
  def __eq__(self, quantity: object, /) -> bool:
421
424
  if quantity == 0:
422
425
  num = float(self)
@@ -429,7 +432,7 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
429
432
  num = self.to_number(quantity._unit)
430
433
  expected = float(quantity._value)
431
434
 
432
- return math.isclose(num, expected)
435
+ return num == expected
433
436
 
434
437
  def __lt__(self, quantity: NullableQuantity[Q_co], /) -> bool:
435
438
  if quantity == 0:
@@ -443,7 +446,7 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
443
446
  num = self.to_number(quantity._unit)
444
447
  expected = float(quantity._value)
445
448
 
446
- return num < expected and not math.isclose(num, expected)
449
+ return num < expected
447
450
 
448
451
  def __le__(self, quantity: object, /) -> bool:
449
452
  if quantity == 0:
@@ -457,7 +460,7 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
457
460
  num = self.to_number(quantity._unit)
458
461
  expected = float(quantity._value)
459
462
 
460
- return num < expected or math.isclose(num, expected)
463
+ return num <= expected
461
464
 
462
465
  def __gt__(self, quantity: object, /) -> bool:
463
466
  if quantity == 0:
@@ -471,7 +474,7 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
471
474
  num = self.to_number(quantity._unit)
472
475
  expected = float(quantity._value)
473
476
 
474
- return num > expected and not math.isclose(num, expected)
477
+ return num > expected
475
478
 
476
479
  def __ge__(self, quantity: object, /) -> bool:
477
480
  if quantity == 0:
@@ -485,7 +488,7 @@ class Quantity(t.Generic[Q_co], metaclass=QuantityMeta):
485
488
  num = self.to_number(quantity._unit)
486
489
  expected = float(quantity._value)
487
490
 
488
- return num > expected or math.isclose(num, expected)
491
+ return num >= expected
489
492
 
490
493
  def __add__(self, quantity: NullableQuantity[Q_co], /) -> Quantity[Q_co]:
491
494
  if quantity == 0:
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
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
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
{u-3.0 → u-4.0}/uv.lock RENAMED
File without changes