peek-python 26.0.0__tar.gz → 26.0.2__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: peek-python
3
- Version: 26.0.0
3
+ Version: 26.0.2
4
4
  Summary: peek - like print, but easy
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/salabim/peek
@@ -266,8 +266,18 @@ called mul(5, 7)
266
266
 
267
267
  As an alternative to `@peek(decorator=True)` , it is possible (and arguably easier) to use `peek.as_decorator()` or `peek.as_d()`:
268
268
 
269
- ``` @peek(decorator=True)
270
- @peek.as_decorator():
269
+ ```
270
+ @peek.as_decorator()
271
+ def mul(x, y):
272
+ return x * y
273
+
274
+ print(mul(5, 7))
275
+ ```
276
+
277
+ It is even possible (and arguably even easier) to omit the `()` if no keyword arguments are required:
278
+
279
+ ```
280
+ @peek.as_decorator # or @peek.as_d
271
281
  def mul(x, y):
272
282
  return x * y
273
283
 
@@ -249,8 +249,18 @@ called mul(5, 7)
249
249
 
250
250
  As an alternative to `@peek(decorator=True)` , it is possible (and arguably easier) to use `peek.as_decorator()` or `peek.as_d()`:
251
251
 
252
- ``` @peek(decorator=True)
253
- @peek.as_decorator():
252
+ ```
253
+ @peek.as_decorator()
254
+ def mul(x, y):
255
+ return x * y
256
+
257
+ print(mul(5, 7))
258
+ ```
259
+
260
+ It is even possible (and arguably even easier) to omit the `()` if no keyword arguments are required:
261
+
262
+ ```
263
+ @peek.as_decorator # or @peek.as_d
254
264
  def mul(x, y):
255
265
  return x * y
256
266
 
@@ -34,7 +34,7 @@ import pprint
34
34
  import builtins
35
35
  import shutil
36
36
 
37
- __version__ = "26.0.0"
37
+ __version__ = "26.0.2"
38
38
 
39
39
  from pathlib import Path
40
40
 
@@ -503,7 +503,8 @@ class _Peek:
503
503
  if this.decorator:
504
504
  if as_str:
505
505
  raise TypeError("as_str may not be True when peek used as decorator")
506
- if any_args:
506
+
507
+ if len(args) > 1 or (len(args) == 1 and not callable(args[0])):
507
508
  raise TypeError("non-keyword arguments are not allowed when peek used as decorator")
508
509
 
509
510
  this._line_number_with_filename_and_parent = f"#{line_number}{filename_name}{parent_function}"
@@ -533,7 +534,11 @@ class _Peek:
533
534
  if not this.do_show() or (not this.show_enter and not this.show_exit):
534
535
  return lambda x: x
535
536
 
536
- return real_decorator
537
+ if len(args) == 0:
538
+ return real_decorator
539
+
540
+ if len(args) == 1 and callable(args[0]):
541
+ return real_decorator(args[0])
537
542
 
538
543
  call_node = executing.Source.executing(call_frame).node
539
544
  if call_node is None:
@@ -679,8 +684,8 @@ class _Peek:
679
684
 
680
685
  return _Peek.return_args(args, this.return_none)
681
686
 
682
- def as_decorator(self, **kwargs):
683
- return self(**kwargs | dict(decorator=True))
687
+ def as_decorator(self, *args, **kwargs):
688
+ return self(*args, **kwargs | dict(decorator=True))
684
689
 
685
690
  as_d = as_decorator
686
691
 
@@ -851,7 +856,12 @@ class _Peek:
851
856
  }
852
857
  if "width" in inspect.signature(self.serialize).parameters:
853
858
  kwargs["width"] = width
854
- return self.add_color_value(self.serialize(obj, **kwargs).replace("\\n", "\n"))
859
+ try:
860
+ serialized = self.serialize(obj, **kwargs)
861
+ except TypeError as e:
862
+ kwargs["sort_dicts"] = False # try without sorting (sometimes required for sympy)
863
+ serialized = self.serialize(obj, **kwargs)
864
+ return self.add_color_value(serialized.replace("\\n", "\n"))
855
865
 
856
866
  def reset(self):
857
867
  reset()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: peek-python
3
- Version: 26.0.0
3
+ Version: 26.0.2
4
4
  Summary: peek - like print, but easy
5
5
  Author-email: Ruud van der Ham <rt.van.der.ham@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/salabim/peek
@@ -266,8 +266,18 @@ called mul(5, 7)
266
266
 
267
267
  As an alternative to `@peek(decorator=True)` , it is possible (and arguably easier) to use `peek.as_decorator()` or `peek.as_d()`:
268
268
 
269
- ``` @peek(decorator=True)
270
- @peek.as_decorator():
269
+ ```
270
+ @peek.as_decorator()
271
+ def mul(x, y):
272
+ return x * y
273
+
274
+ print(mul(5, 7))
275
+ ```
276
+
277
+ It is even possible (and arguably even easier) to omit the `()` if no keyword arguments are required:
278
+
279
+ ```
280
+ @peek.as_decorator # or @peek.as_d
271
281
  def mul(x, y):
272
282
  return x * y
273
283
 
@@ -10,7 +10,7 @@ authors = [
10
10
  { name = "Ruud van der Ham", email = "rt.van.der.ham@gmail.com" },
11
11
  ]
12
12
  description = "peek - like print, but easy"
13
- version = "26.0.0"
13
+ version = "26.0.2"
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.9"
16
16
  dependencies = [
@@ -10,7 +10,8 @@ import shutil
10
10
  from pathlib import Path
11
11
 
12
12
 
13
- import os, sys # three lines to use the local package and chdir
13
+ import os, sys # three lines to use the local package and chdir
14
+
14
15
  os.chdir(os.path.dirname(__file__))
15
16
  sys.path.insert(0, os.path.dirname(__file__) + "/../")
16
17
 
@@ -18,23 +19,23 @@ import peek
18
19
 
19
20
  peek = peek.new(ignore_toml=True)
20
21
 
21
- dark_black=peek.ANSI.dark_black
22
- dark_red=peek.ANSI.dark_red
23
- dark_green=peek.ANSI.dark_green
24
- dark_yellow=peek.ANSI.dark_yellow
25
- dark_blue=peek.ANSI.dark_blue
26
- dark_magenta=peek.ANSI.dark_magenta
27
- dark_cyan=peek.ANSI.dark_cyan
28
- dark_white=peek.ANSI.dark_white
29
- black=peek.ANSI.black
30
- red=peek.ANSI.red
31
- green=peek.ANSI.green
32
- yellow=peek.ANSI.yellow
33
- blue=peek.ANSI.blue
34
- magenta=peek.ANSI.magenta
35
- cyan=peek.ANSI.cyan
36
- white=peek.ANSI.white
37
- reset=peek.ANSI.reset
22
+ dark_black = peek.ANSI.dark_black
23
+ dark_red = peek.ANSI.dark_red
24
+ dark_green = peek.ANSI.dark_green
25
+ dark_yellow = peek.ANSI.dark_yellow
26
+ dark_blue = peek.ANSI.dark_blue
27
+ dark_magenta = peek.ANSI.dark_magenta
28
+ dark_cyan = peek.ANSI.dark_cyan
29
+ dark_white = peek.ANSI.dark_white
30
+ black = peek.ANSI.black
31
+ red = peek.ANSI.red
32
+ green = peek.ANSI.green
33
+ yellow = peek.ANSI.yellow
34
+ blue = peek.ANSI.blue
35
+ magenta = peek.ANSI.magenta
36
+ cyan = peek.ANSI.cyan
37
+ white = peek.ANSI.white
38
+ reset = peek.ANSI.reset
38
39
 
39
40
  Pythonista = sys.platform == "ios"
40
41
 
@@ -301,12 +302,12 @@ def test_as_str():
301
302
 
302
303
  with pytest.raises(TypeError):
303
304
 
304
- @peek(decorator=True,as_str=True)
305
+ @peek(decorator=True, as_str=True)
305
306
  def add2(x):
306
307
  return x + 2
307
308
 
308
309
  with pytest.raises(TypeError):
309
- with peek(context_manager=True,as_str=True):
310
+ with peek(context_manager=True, as_str=True):
310
311
  pass
311
312
 
312
313
  with peek.preserve():
@@ -325,7 +326,6 @@ def test_colored_end(capsys):
325
326
  assert out == f"{red}hello='world'{reset}{red}|{reset}"
326
327
 
327
328
 
328
- @pytest.mark.skipif(Pythonista, reason="Pythonista problem")
329
329
  def test_print(capsys):
330
330
  peek.print(*range(4))
331
331
  peek.print(*range(4), sep="|")
@@ -505,6 +505,7 @@ def test_color(capsys):
505
505
  s = peek(hello, as_str=True, color="blue")
506
506
  assert s == f"{blue}hello='world'{reset}\n"
507
507
 
508
+
508
509
  def test_numeric_colors():
509
510
  with peek.preserve():
510
511
  hello = "world"
@@ -531,18 +532,20 @@ def test_numeric_colors():
531
532
  s = peek(hello, as_str=True, color=4)
532
533
  assert s == f"{blue}hello='world'{reset}\n"
533
534
 
535
+
534
536
  def test_color_alias():
535
537
  with peek.preserve():
536
- peek.col="red"
538
+ peek.col = "red"
537
539
  assert peek.color == peek.col == peek.c == "red"
538
- peek.c="green"
540
+ peek.c = "green"
539
541
  assert peek.color == peek.col == peek.c == "green"
540
542
 
541
- peek.col_val="red"
543
+ peek.col_val = "red"
542
544
  assert peek.color_value == peek.col_val == peek.cv == "red"
543
- peek.cv="green"
545
+ peek.cv = "green"
544
546
  assert peek.color_value == peek.col_val == peek.cv == "green"
545
547
 
548
+
546
549
  def test_incorrect_filter():
547
550
  with pytest.raises(AttributeError):
548
551
  peek.filter = "color='blue'"
@@ -558,15 +561,15 @@ def test_decorator(capsys):
558
561
  def div(x, y):
559
562
  return x / y
560
563
 
561
- @peek(decorator=True,show_enter=False)
564
+ @peek(decorator=True, show_enter=False)
562
565
  def add(x, y):
563
566
  return x + y
564
567
 
565
- @peek(decorator=True,show_exit=False)
568
+ @peek(decorator=True, show_exit=False)
566
569
  def sub(x, y):
567
570
  return x - y
568
571
 
569
- @peek(decorator=True,show_enter=False, show_exit=False)
572
+ @peek(decorator=True, show_enter=False, show_exit=False)
570
573
  def pow(x, y):
571
574
  return x**y
572
575
 
@@ -590,6 +593,14 @@ called sub(10, 2)
590
593
  def test_decorator_edge_cases(capsys):
591
594
  peek.fix_perf_counter(0)
592
595
 
596
+ @peek.as_decorator
597
+ def add2(x):
598
+ return x + 2
599
+
600
+ assert add2(2) == 4
601
+ out, err = capsys.readouterr()
602
+ assert out == "called add2(2)\nreturned 4 from add2(2) in 0.000000 seconds\n"
603
+
593
604
  @peek(decorator=True)
594
605
  def mul(x, y, factor=1):
595
606
  return x * y * factor
@@ -609,6 +620,20 @@ called mul(5, 6, factor=10)
609
620
  returned 300 from mul(5, 6, factor=10) in 0.000000 seconds
610
621
  """
611
622
  )
623
+ a = 1
624
+
625
+ with pytest.raises(TypeError):
626
+
627
+ @peek(a, decorator=True)
628
+ def add2(x):
629
+ return x + 2
630
+
631
+ with pytest.raises(TypeError):
632
+
633
+ @peek.as_decorator(a)
634
+ def add2(x):
635
+ return x + 2
636
+
612
637
  peek.fix_perf_counter(None)
613
638
 
614
639
 
@@ -617,7 +642,7 @@ def test_decorator_with_methods(capsys):
617
642
  def __init__(self, value):
618
643
  self.value = value
619
644
 
620
- @peek(decorator=True,show_exit=False)
645
+ @peek(decorator=True, show_exit=False)
621
646
  def __mul__(self, other):
622
647
  if isinstance(other, Number):
623
648
  return self.value * other.value
@@ -648,38 +673,39 @@ called __mul__(Number(2), Number(3))
648
673
  """
649
674
  )
650
675
 
676
+
651
677
  def test_as_decorator(capsys):
652
678
  @peek.as_decorator()
653
679
  def add2(x):
654
- return x+2
655
-
680
+ return x + 2
681
+
656
682
  add2(3)
657
683
  out, err = capsys.readouterr()
658
684
  assert out.startswith("called add2(3)\nreturned 5 from add2(3) in ")
659
685
 
660
686
  @peek.as_d()
661
687
  def add2(x):
662
- return x+2
663
-
688
+ return x + 2
689
+
664
690
  add2(3)
665
691
  out, err = capsys.readouterr()
666
692
  assert out.startswith("called add2(3)\nreturned 5 from add2(3) in ")
667
693
 
694
+
668
695
  def test_as_context_manager(capsys):
669
696
  with peek.as_context_manager():
670
697
  print(1)
671
-
698
+
672
699
  out, err = capsys.readouterr()
673
700
  assert out.startswith("enter\n1\nexit in ")
674
701
 
675
702
  with peek.as_cm():
676
703
  print(1)
677
-
704
+
678
705
  out, err = capsys.readouterr()
679
706
  assert out.startswith("enter\n1\nexit in ")
680
707
 
681
708
 
682
- @pytest.mark.skipif(Pythonista, reason="Pythonista problem")
683
709
  def test_context_manager(capsys):
684
710
  peek.fix_perf_counter(0)
685
711
  with peek(context_manager=True):
@@ -955,7 +981,6 @@ def test_traceback(capsys):
955
981
  assert out.count("traceback") == 2
956
982
 
957
983
 
958
- @pytest.mark.skipif(Pythonista, reason="Pythonista problem")
959
984
  def test_check_output(capsys, tmpdir):
960
985
  with peek.preserve():
961
986
  x1_file = tmpdir / "x1.py"
File without changes