istr-python 1.1.30__tar.gz → 1.1.31__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.30
3
+ Version: 1.1.31
4
4
  Summary: istr - strings you can count on
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/salabim/istr
@@ -5,7 +5,7 @@
5
5
  # |_||___/ \__||_|
6
6
  # strings you can count on
7
7
 
8
- __version__ = "1.1.30"
8
+ __version__ = "1.1.31"
9
9
  import functools
10
10
  import itertools
11
11
  import types
@@ -15,7 +15,7 @@ import math
15
15
  import operator
16
16
  import copy
17
17
  import bisect
18
-
18
+ import collections
19
19
  """
20
20
  Note: the changelog is in changelog.md
21
21
 
@@ -404,23 +404,23 @@ class istr(str):
404
404
  return not istr.is_divisible_by(self, 2)
405
405
 
406
406
  def is_palindrome(self):
407
- self_as_str = str(self)
407
+ self_as_str = istr.interpret_as_str(self)
408
408
  return self_as_str == self_as_str[::-1]
409
409
 
410
410
  def is_non_decreasing(self):
411
- self_as_str = str(self)
411
+ self_as_str = istr.interpret_as_str(self)
412
412
  return all(i0 <= i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
413
413
 
414
414
  def is_non_increasing(self):
415
- self_as_str = str(self)
415
+ self_as_str = istr.interpret_as_str(self)
416
416
  return all(i0 >= i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
417
417
 
418
418
  def is_increasing(self):
419
- self_as_str = str(self)
419
+ self_as_str = istr.interpret_as_str(self)
420
420
  return all(i0 < i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
421
421
 
422
422
  def is_decreasing(self):
423
- self_as_str = str(self)
423
+ self_as_str = istr.interpret_as_str(self)
424
424
  return all(i0 > i1 for i0, i1 in zip(self_as_str, self_as_str[1:]))
425
425
 
426
426
  def is_divisible_by(self, divisor):
@@ -698,20 +698,29 @@ class istr(str):
698
698
  if isinstance(self, istr):
699
699
  if not self.is_int():
700
700
  raise TypeError(f"not interpretable as int: {self._frepr(self)}")
701
- n = self._as_int
702
- else:
703
- n = int(self)
704
- return n
701
+ return self._as_int
702
+ if isinstance(self, collections.abc.Iterable) and not isinstance(self,str):
703
+ return int(istr.join(self))
704
+
705
+ return int(self)
705
706
 
706
707
 
707
708
  def interpret_as_float(self):
708
709
  if isinstance(self, istr):
709
710
  if not self.is_int():
710
711
  raise TypeError(f"not interpretable as float: {self._frepr(self)}")
711
- n = self._as_int
712
- else:
713
- n = float(self)
714
- return n
712
+ return self._as_int
713
+ if isinstance(self, collections.abc.Iterable) and not isinstance(self,str):
714
+ return float(istr.join(self))
715
+
716
+ return float(self)
717
+
718
+ def interpret_as_str(self):
719
+
720
+ if isinstance(self, collections.abc.Iterable) and not isinstance(self,str):
721
+ return istr.join(self)
722
+
723
+ return str(self)
715
724
 
716
725
  def _str_method(self, name, *args, **kwargs):
717
726
  return self.__class__(getattr(super(), name)(*args, **kwargs))
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: istr-python
3
- Version: 1.1.30
3
+ Version: 1.1.31
4
4
  Summary: istr - strings you can count on
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/salabim/istr
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "istr - strings you can count on"
13
- version = "1.1.30"
13
+ version = "1.1.31"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.10"
16
16
  dependencies = []
@@ -987,24 +987,53 @@ def test_decompose():
987
987
  with pytest.raises(ValueError):
988
988
  istr(123).decompose("xy1")
989
989
 
990
+
990
991
  def test_ceil():
991
- assert istr(1000).ceil()==1000
992
- assert istr(1000).ceil(1)==1000
993
- assert istr(1000).ceil(2)==1000
994
- assert istr(1000).ceil(3)==1002
995
- assert istr.ceil(1000)==1000
996
- assert istr.ceil(1000,1)==1000
997
- assert istr.ceil(1000.2,1).equals(istr(1001))
992
+ assert istr(1000).ceil() == 1000
993
+ assert istr(1000).ceil(1) == 1000
994
+ assert istr(1000).ceil(2) == 1000
995
+ assert istr(1000).ceil(3) == 1002
996
+ assert istr.ceil(1000) == 1000
997
+ assert istr.ceil(1000, 1) == 1000
998
+ assert istr.ceil(1000.2, 1).equals(istr(1001))
999
+
998
1000
 
999
1001
  def test_floor():
1000
- assert istr(1000).floor()==1000
1001
- assert istr(1000).floor(1)==1000
1002
- assert istr(1000).floor(2)==1000
1003
- assert istr(1000).floor(3)==999
1004
- assert istr.floor(1000)==1000
1005
- assert istr.floor(1000,1)==1000
1006
- assert istr.floor(1000.2,1).equals(istr(1000))
1007
-
1002
+ assert istr(1000).floor() == 1000
1003
+ assert istr(1000).floor(1) == 1000
1004
+ assert istr(1000).floor(2) == 1000
1005
+ assert istr(1000).floor(3) == 999
1006
+ assert istr.floor(1000) == 1000
1007
+ assert istr.floor(1000, 1) == 1000
1008
+ assert istr.floor(1000.2, 1).equals(istr(1000))
1009
+
1010
+
1011
+ def test_tuple_join():
1012
+ assert istr.is_prime(istr(1, 3))
1013
+ assert istr.is_square(istr(6, 4))
1014
+ assert istr.is_cube(istr(6, 4))
1015
+ assert istr.is_power_of(istr(3, 2), 5)
1016
+ assert istr.is_odd(istr(1, 3))
1017
+ assert istr.is_even(istr(1, 2))
1018
+ assert istr.is_triangular(istr(1, 0))
1019
+ assert istr.is_increasing(istr(1, 2))
1020
+ assert istr.is_non_decreasing(istr(1, 2, 2, 3))
1021
+ assert istr.is_decreasing(istr(2, 1))
1022
+ assert istr.is_non_increasing(istr(3, 2, 2, 1))
1023
+
1024
+ assert not istr.is_prime(istr(1, 4))
1025
+ assert not istr.is_square(istr(6, 5))
1026
+ assert not istr.is_cube(istr(6, 5))
1027
+ assert not istr.is_power_of(istr(3, 3), 5)
1028
+ assert not istr.is_odd(istr(1, 4))
1029
+ assert not istr.is_even(istr(1, 3))
1030
+ assert not istr.is_triangular(istr(1, 1))
1031
+ assert not istr.is_increasing(istr(1, 1))
1032
+ assert not istr.is_non_decreasing(istr(1, 2, 2, 1))
1033
+ assert not istr.is_decreasing(istr(2, 2))
1034
+ assert not istr.is_non_increasing(istr(3, 2, 2, 4))
1035
+
1036
+
1008
1037
  def test_compose():
1009
1038
  global x, y, z, _
1010
1039
  x = 1
File without changes
File without changes