istr-python 1.0.10__tar.gz → 1.0.11__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.1
2
2
  Name: istr-python
3
- Version: 1.0.10
3
+ Version: 1.0.11
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.0.10"
8
+ __version__ = "1.0.11"
9
9
  import functools
10
10
  import math
11
11
  import itertools
@@ -243,9 +243,9 @@ class istr(str):
243
243
  return value
244
244
  if isinstance(value, dict):
245
245
  return type(value)((k, cls(v)) for k, v in value.items())
246
- if not isinstance(value, (str, type)) and hasattr(value, "__iter__"):
246
+ if not isinstance(value, (str, type)) and hasattr(value, "__iter__"):
247
247
  if hasattr(value, "__next__"):
248
- return map(functools.partial(cls), value)
248
+ return map(functools.partial(cls), value)
249
249
  return type(value)(map(functools.partial(cls), value))
250
250
  as_int = cls._to_int(value)
251
251
  if isinstance(value, str):
@@ -355,7 +355,7 @@ class istr(str):
355
355
  def is_square(self):
356
356
  if not self.is_int():
357
357
  raise TypeError(f"not interpretable as int: {self._frepr(self)}")
358
- return self == math.isqrt(self._as_int)**2
358
+ return self._as_int >= 0 and self == math.isqrt(self._as_int) ** 2
359
359
 
360
360
  def is_prime(self):
361
361
  if not self.is_int():
@@ -371,8 +371,6 @@ class istr(str):
371
371
  return False
372
372
  return True
373
373
 
374
-
375
-
376
374
  def __or__(self, other):
377
375
  try:
378
376
  return self.__class__(str(self).__add__(other))
@@ -574,8 +572,7 @@ class istr(str):
574
572
 
575
573
 
576
574
  def main():
577
- for i in range(100):
578
- print(i, istr(i).is_prime(),istr(i).is_square())
575
+ ...
579
576
 
580
577
 
581
578
  if __name__ == "__main__":
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: istr-python
3
- Version: 1.0.10
3
+ Version: 1.0.11
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
@@ -8,7 +8,7 @@ authors = [
8
8
  {name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com"}
9
9
  ]
10
10
  description = "istr - strings you can count on"
11
- version = "1.0.10"
11
+ version = "1.0.11"
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.7"
14
14
  dependencies = [
@@ -304,13 +304,23 @@ def test_even_odd():
304
304
  assert not istr(1).is_even()
305
305
 
306
306
  assert istr(12345678).is_even()
307
-
307
+ with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
308
+ istr("a").is_odd()
309
+ with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
310
+ istr("a").is_even()
311
+
312
+
308
313
  def test_is_square():
314
+ assert not istr(-1).is_square()
315
+ assert istr(0).is_square()
309
316
  assert istr(1).is_square()
310
317
  assert not istr(2).is_square()
311
318
  assert istr(4).is_square()
312
319
  assert istr(16).is_square()
313
320
  assert not istr(99).is_square()
321
+ with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
322
+ istr("a").is_square()
323
+
314
324
 
315
325
  def test_is_prime():
316
326
  assert not istr(0).is_prime()
@@ -320,10 +330,8 @@ def test_is_prime():
320
330
  assert not istr(4).is_prime()
321
331
  assert istr(97).is_prime()
322
332
  assert not istr(99).is_prime()
323
-
324
-
325
-
326
-
333
+ with pytest.raises(TypeError, match=re.escape(f"not interpretable as int")):
334
+ istr("a").is_prime()
327
335
 
328
336
 
329
337
  def test_join():
@@ -574,12 +582,14 @@ def test_base():
574
582
  with istr.base(10):
575
583
  assert a * a == 225
576
584
 
577
- def test_is_divisible():
585
+
586
+ def test_is_divisible():
578
587
  assert istr(18).is_divisible_by(3)
579
588
  assert istr(18).is_divisible_by(istr(3))
580
589
  assert not istr(19).is_divisible_by(3)
581
590
  assert not istr(19).is_divisible_by(istr(3))
582
-
591
+
592
+
583
593
  def test_digits():
584
594
  assert istr.digits().equals(istr("0123456789"))
585
595
  assert istr.digits("").equals(istr("0123456789"))
@@ -647,8 +657,7 @@ def test_all_distinct():
647
657
 
648
658
 
649
659
  def test_subclassing():
650
- class jstr(istr):
651
- ...
660
+ class jstr(istr): ...
652
661
 
653
662
  assert jstr(5).equals(jstr(5))
654
663
  assert repr(jstr(*range(3))) == "(jstr('0'), jstr('1'), jstr('2'))"
@@ -656,4 +665,3 @@ def test_subclassing():
656
665
 
657
666
  if __name__ == "__main__":
658
667
  pytest.main(["-vv", "-s", "-x", __file__])
659
-
File without changes
File without changes