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.
- {istr_python-1.1.30 → istr_python-1.1.31}/PKG-INFO +1 -1
- {istr_python-1.1.30 → istr_python-1.1.31}/istr/istr.py +24 -15
- {istr_python-1.1.30 → istr_python-1.1.31}/istr_python.egg-info/PKG-INFO +1 -1
- {istr_python-1.1.30 → istr_python-1.1.31}/pyproject.toml +1 -1
- {istr_python-1.1.30 → istr_python-1.1.31}/tests/test_istr.py +44 -15
- {istr_python-1.1.30 → istr_python-1.1.31}/README.md +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/istr/LICENSE.txt +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/istr/__init__.py +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/istr_python.egg-info/SOURCES.txt +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/istr_python.egg-info/dependency_links.txt +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/istr_python.egg-info/top_level.txt +0 -0
- {istr_python-1.1.30 → istr_python-1.1.31}/setup.cfg +0 -0
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
# |_||___/ \__||_|
|
|
6
6
|
# strings you can count on
|
|
7
7
|
|
|
8
|
-
__version__ = "1.1.
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
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
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
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))
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|