|
34 | 34 |
|
35 | 35 | def aliasing_mutation(c: Canvas) -> None: |
36 | 36 | """Two names binding to one mutable list, before and after a mutation.""" |
37 | | - c.tag(0, 12, "before") |
38 | | - c.name_box(0, 18, "first") |
39 | | - c.name_box(0, 48, "second") |
40 | | - c.closed_arrow(60, 30, 86, 46, emphasis=False) |
41 | | - c.closed_arrow(60, 60, 86, 46, emphasis=False) |
42 | | - c.object_box(88, 32, "", '["python"]', w=88, h=28) |
43 | | - |
44 | | - c.tag(0, 100, "after append") |
45 | | - c.name_box(0, 108, "first") |
46 | | - c.name_box(0, 138, "second") |
47 | | - c.closed_arrow(60, 120, 86, 136, emphasis=False) |
48 | | - c.closed_arrow(60, 150, 86, 136, emphasis=False) |
49 | | - c.object_box(88, 122, "", '["python","workers"]', w=130, h=28) |
| 37 | + c.two_names_one_object(0, 18, "before", "first", "second", '["python"]', object_w=88) |
| 38 | + c.two_names_one_object(0, 108, "after append", "first", "second", |
| 39 | + '["python","workers"]', object_w=130) |
50 | 40 |
|
51 | 41 |
|
52 | 42 | def tuple_no_mutation(c: Canvas) -> None: |
53 | 43 | """The contrast: two names binding to one immutable tuple — no mutation possible.""" |
54 | | - c.tag(0, 12, "tuple — frozen") |
55 | | - c.name_box(0, 18, "first") |
56 | | - c.name_box(0, 48, "second") |
57 | | - c.closed_arrow(60, 30, 86, 46, emphasis=False) |
58 | | - c.closed_arrow(60, 60, 86, 46, emphasis=False) |
59 | | - c.object_box(88, 32, "", '("python",)', w=110, h=28) |
60 | | - |
61 | | - c.tag(0, 100, "no .append") |
62 | | - c.name_box(0, 108, "first") |
63 | | - c.name_box(0, 138, "second") |
64 | | - c.closed_arrow(60, 120, 86, 136, emphasis=False) |
65 | | - c.closed_arrow(60, 150, 86, 136, emphasis=False) |
66 | | - c.object_box(88, 122, "", '("python",)', w=110, h=28) |
| 44 | + c.two_names_one_object(0, 18, "tuple — frozen", "first", "second", |
| 45 | + '("python",)', object_w=110) |
| 46 | + c.two_names_one_object(0, 108, "no .append", "first", "second", |
| 47 | + '("python",)', object_w=110) |
67 | 48 | c.label(150, 170, "tuples raise AttributeError", anchor="middle") |
68 | 49 |
|
69 | 50 |
|
@@ -597,14 +578,7 @@ def dataclass_fields(c: Canvas) -> None: |
597 | 578 |
|
598 | 579 | def class_triangle(c: Canvas) -> None: |
599 | 580 | """Classes · instance → class → type — every Python value sits on this triangle.""" |
600 | | - c.dot(20, 28) |
601 | | - c.label(20, 54, "instance", anchor="middle") |
602 | | - c.closed_arrow(26, 28, 86, 28, emphasis=False) |
603 | | - c.frame(88, 10, 60, 36, label="class") |
604 | | - c.mono(118, 32, "Class") |
605 | | - c.closed_arrow(148, 28, 208, 28, emphasis=False) |
606 | | - c.frame(210, 10, 60, 36, label="type") |
607 | | - c.mono(240, 32, "type") |
| 581 | + c.type_triangle("type", "type") |
608 | 582 |
|
609 | 583 |
|
610 | 584 | def exception_cause_context(c: Canvas) -> None: |
@@ -729,17 +703,15 @@ def sort_stability(c: Canvas) -> None: |
729 | 703 | def kw_only_separator(c: Canvas) -> None: |
730 | 704 | """Keyword-only arguments · `*` divides positional from keyword-only.""" |
731 | 705 | c.mono(0, 18, "def f(a, b, *, c, d): …", anchor="start") |
732 | | - # JetBrains Mono advances ~6px per char at fs=10; '*' sits at index 12. |
733 | | - c.dashed(75, 22, 75, 38) |
| 706 | + c.mono_divider(0, 12, 22, 38) # the '*' sits at index 12 |
734 | 707 | c.label(33, 50, "positional or kw", anchor="middle") |
735 | 708 | c.label(120, 50, "keyword only", anchor="middle") |
736 | 709 |
|
737 | 710 |
|
738 | 711 | def positional_only_separator(c: Canvas) -> None: |
739 | 712 | """Positional-only parameters · `/` divides positional-only from positional-or-kw.""" |
740 | 713 | c.mono(0, 18, "def f(a, b, /, c, d): …", anchor="start") |
741 | | - # JetBrains Mono advances ~6px per char at fs=10; '/' sits at index 12. |
742 | | - c.dashed(75, 22, 75, 38) |
| 714 | + c.mono_divider(0, 12, 22, 38) # the '/' sits at index 12 |
743 | 715 | c.label(33, 50, "positional only", anchor="middle") |
744 | 716 | c.label(120, 50, "positional or kw", anchor="middle") |
745 | 717 |
|
@@ -899,14 +871,7 @@ def property_fork(c: Canvas) -> None: |
899 | 871 |
|
900 | 872 | def metaclass_triangle(c: Canvas) -> None: |
901 | 873 | """Metaclasses · instance → class → metaclass; the metaclass is the type of the class.""" |
902 | | - c.dot(20, 30) |
903 | | - c.label(20, 56, "instance", anchor="middle") |
904 | | - c.closed_arrow(26, 30, 86, 30, emphasis=False) |
905 | | - c.frame(88, 12, 60, 36, label="class") |
906 | | - c.mono(118, 34, "Class") |
907 | | - c.closed_arrow(148, 30, 218, 30, emphasis=False) |
908 | | - c.frame(220, 12, 80, 36, label="metaclass") |
909 | | - c.mono(260, 34, "type") |
| 874 | + c.type_triangle("metaclass", "type", third_w=80) |
910 | 875 |
|
911 | 876 |
|
912 | 877 | def sys_path_resolution(c: Canvas) -> None: |
|
0 commit comments