memory-graph 0.3.55__tar.gz → 0.3.57__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.
Files changed (146) hide show
  1. {memory_graph-0.3.55/memory_graph.egg-info → memory_graph-0.3.57}/PKG-INFO +33 -28
  2. {memory_graph-0.3.55 → memory_graph-0.3.57}/README.md +31 -1
  3. memory_graph-0.3.57/images/add_one.png +0 -0
  4. memory_graph-0.3.57/images/avltree_key_value.png +0 -0
  5. memory_graph-0.3.57/images/avltree_leaf.png +0 -0
  6. memory_graph-0.3.57/images/avltree_linear.png +0 -0
  7. memory_graph-0.3.57/images/avltree_table.png +0 -0
  8. memory_graph-0.3.57/images/bin_search.png +0 -0
  9. memory_graph-0.3.57/images/bin_search_linear.png +0 -0
  10. memory_graph-0.3.57/images/bin_tree.png +0 -0
  11. memory_graph-0.3.57/images/binary.gif +0 -0
  12. memory_graph-0.3.57/images/copy_immutable.png +0 -0
  13. memory_graph-0.3.57/images/copy_method.png +0 -0
  14. memory_graph-0.3.57/images/copy_mix.png +0 -0
  15. memory_graph-0.3.57/images/copy_mutable.png +0 -0
  16. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/create_images.sh +1 -0
  17. memory_graph-0.3.57/images/debugging.gif +0 -0
  18. memory_graph-0.3.57/images/embedded1.png +0 -0
  19. memory_graph-0.3.57/images/embedded2.png +0 -0
  20. memory_graph-0.3.57/images/extension_numpy.png +0 -0
  21. memory_graph-0.3.57/images/extension_pandas.png +0 -0
  22. memory_graph-0.3.57/images/factorial.gif +0 -0
  23. memory_graph-0.3.57/images/hash_set.png +0 -0
  24. memory_graph-0.3.57/images/hidden_edges.png +0 -0
  25. memory_graph-0.3.57/images/immutable1.png +0 -0
  26. memory_graph-0.3.57/images/immutable2.png +0 -0
  27. memory_graph-0.3.57/images/introspect_depth.png +0 -0
  28. memory_graph-0.3.57/images/linked_list.png +0 -0
  29. memory_graph-0.3.57/images/many_types.png +0 -0
  30. memory_graph-0.3.57/images/mutable1.png +0 -0
  31. memory_graph-0.3.57/images/mutable2.png +0 -0
  32. memory_graph-0.3.57/images/power_set.gif +0 -0
  33. memory_graph-0.3.57/images/rebinding1.png +0 -0
  34. memory_graph-0.3.57/images/rebinding2.png +0 -0
  35. memory_graph-0.3.57/images/wrap_int.png +0 -0
  36. memory_graph-0.3.57/images/wrap_int.py +16 -0
  37. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/__init__.py +1 -1
  38. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config.py +3 -0
  39. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config_default.py +3 -0
  40. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/memory_to_nodes.py +3 -3
  41. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/utils.py +1 -1
  42. {memory_graph-0.3.55 → memory_graph-0.3.57/memory_graph.egg-info}/PKG-INFO +33 -28
  43. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/SOURCES.txt +2 -0
  44. {memory_graph-0.3.55 → memory_graph-0.3.57}/pyproject.toml +3 -3
  45. memory_graph-0.3.55/images/add_one.png +0 -0
  46. memory_graph-0.3.55/images/avltree_key_value.png +0 -0
  47. memory_graph-0.3.55/images/avltree_leaf.png +0 -0
  48. memory_graph-0.3.55/images/avltree_linear.png +0 -0
  49. memory_graph-0.3.55/images/avltree_table.png +0 -0
  50. memory_graph-0.3.55/images/bin_search.png +0 -0
  51. memory_graph-0.3.55/images/bin_search_linear.png +0 -0
  52. memory_graph-0.3.55/images/bin_tree.png +0 -0
  53. memory_graph-0.3.55/images/binary.gif +0 -0
  54. memory_graph-0.3.55/images/copy_immutable.png +0 -0
  55. memory_graph-0.3.55/images/copy_method.png +0 -0
  56. memory_graph-0.3.55/images/copy_mix.png +0 -0
  57. memory_graph-0.3.55/images/copy_mutable.png +0 -0
  58. memory_graph-0.3.55/images/debugging.gif +0 -0
  59. memory_graph-0.3.55/images/embedded1.png +0 -0
  60. memory_graph-0.3.55/images/embedded2.png +0 -0
  61. memory_graph-0.3.55/images/extension_numpy.png +0 -0
  62. memory_graph-0.3.55/images/extension_pandas.png +0 -0
  63. memory_graph-0.3.55/images/factorial.gif +0 -0
  64. memory_graph-0.3.55/images/hash_set.png +0 -0
  65. memory_graph-0.3.55/images/hidden_edges.png +0 -0
  66. memory_graph-0.3.55/images/immutable1.png +0 -0
  67. memory_graph-0.3.55/images/immutable2.png +0 -0
  68. memory_graph-0.3.55/images/introspect_depth.png +0 -0
  69. memory_graph-0.3.55/images/linked_list.png +0 -0
  70. memory_graph-0.3.55/images/many_types.png +0 -0
  71. memory_graph-0.3.55/images/mutable1.png +0 -0
  72. memory_graph-0.3.55/images/mutable2.png +0 -0
  73. memory_graph-0.3.55/images/power_set.gif +0 -0
  74. memory_graph-0.3.55/images/rebinding1.png +0 -0
  75. memory_graph-0.3.55/images/rebinding2.png +0 -0
  76. {memory_graph-0.3.55 → memory_graph-0.3.57}/LICENSE.txt +0 -0
  77. {memory_graph-0.3.55 → memory_graph-0.3.57}/MANIFEST.in +0 -0
  78. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/add_one.py +0 -0
  79. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree.py +0 -0
  80. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree_dir.png +0 -0
  81. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree_fail.png +0 -0
  82. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_search.py +0 -0
  83. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_tree.gif +0 -0
  84. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_tree.py +0 -0
  85. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/binary.py +0 -0
  86. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/colab_example.png +0 -0
  87. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_immutable.py +0 -0
  88. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_method.py +0 -0
  89. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_mix.py +0 -0
  90. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_mutable.py +0 -0
  91. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/create_gif.sh +0 -0
  92. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/debug_vscode.png +0 -0
  93. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/debugging.py +0 -0
  94. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_numpy.py +0 -0
  95. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_pandas.py +0 -0
  96. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_torch.png +0 -0
  97. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_torch.py +0 -0
  98. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/factorial.py +0 -0
  99. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hash_set.gif +0 -0
  100. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hash_set.py +0 -0
  101. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hidden_edges.py +0 -0
  102. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/immutable.py +0 -0
  103. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/introspect_depth.py +0 -0
  104. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/ipython.png +0 -0
  105. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/jupyter_example.png +0 -0
  106. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/linked_list.gif +0 -0
  107. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/linked_list.py +0 -0
  108. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/many_types.py +0 -0
  109. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/marimo_example.png +0 -0
  110. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/memory_graph_web_debugger.png +0 -0
  111. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/mutable.py +0 -0
  112. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/name_rebinding.py +0 -0
  113. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/not_node_types.py +0 -0
  114. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/power_set.py +0 -0
  115. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/uva.png +0 -0
  116. {memory_graph-0.3.55 → memory_graph-0.3.57}/images/vscode_copying.gif +0 -0
  117. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/call_stack.py +0 -0
  118. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config_helpers.py +0 -0
  119. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_numpy.py +0 -0
  120. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_pandas.py +0 -0
  121. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_torch.py +0 -0
  122. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/html_table.py +0 -0
  123. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/list_view.py +0 -0
  124. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_base.py +0 -0
  125. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_key_value.py +0 -0
  126. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_leaf.py +0 -0
  127. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_linear.py +0 -0
  128. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_table.py +0 -0
  129. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/sequence.py +0 -0
  130. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slicer.py +0 -0
  131. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices.py +0 -0
  132. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices_iterator.py +0 -0
  133. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices_table_iterator.py +0 -0
  134. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test.py +0 -0
  135. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_max_graph_depth.py +0 -0
  136. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_memory_graph.py +0 -0
  137. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_memory_to_nodes.py +0 -0
  138. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_sequence.py +0 -0
  139. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slicer.py +0 -0
  140. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slices.py +0 -0
  141. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slices_iterator.py +0 -0
  142. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/dependency_links.txt +0 -0
  143. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/requires.txt +0 -0
  144. {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/top_level.txt +0 -0
  145. {memory_graph-0.3.55 → memory_graph-0.3.57}/setup.cfg +0 -0
  146. {memory_graph-0.3.55 → memory_graph-0.3.57}/setup.py +0 -0
@@ -1,34 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.55
3
+ Version: 0.3.57
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
- License: BSD 2-Clause License
7
-
8
- Copyright (c) 2017, pyexample
9
- All rights reserved.
10
-
11
- Redistribution and use in source and binary forms, with or without
12
- modification, are permitted provided that the following conditions are met:
13
-
14
- * Redistributions of source code must retain the above copyright notice, this
15
- list of conditions and the following disclaimer.
16
-
17
- * Redistributions in binary form must reproduce the above copyright notice,
18
- this list of conditions and the following disclaimer in the documentation
19
- and/or other materials provided with the distribution.
20
-
21
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
6
+ License-Expression: BSD-2-Clause
32
7
  Project-URL: Homepage, https://github.com/bterwijn/memory_graph
33
8
  Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
34
9
  Classifier: Development Status :: 4 - Beta
@@ -362,9 +337,33 @@ In the printed output only `a` is changed as a result of the function call:
362
337
  ```
363
338
  a:[4, 3, 2, 1] b:(4, 3, 2) c:[4, 3, 2]
364
339
  ```
365
-
366
340
  This is because `b` is of immutable type 'tuple' so its value gets copied automatically when it is changed. And because the function is called with a copy of `c`, its original value is not changed by the function. The value of variable `a` is the only value of mutable type that is shared between the root stack frame **'0: \<module>'** and the **'1: add_one'** stack frame of the function so only that variable is affected as a result of the function call. The other changes remain confined to the local variables of the ```add_one()``` function.
367
341
 
342
+ ## Function Call That Changes 'int' Value ##
343
+ Even though `int` is an immutable type, so an `int` value can not be changed by directly passing it to a function, we can still change it by wrapping it in a mutable container.
344
+
345
+ ```python
346
+ import memory_graph as mg
347
+
348
+ def add_one(a, b):
349
+ a += 1 # change remains confined to 'a' in the add_one function
350
+ b[0] += 1 # change also effects 'b' outside of the add_one function
351
+ mg.show(mg.stack())
352
+
353
+ a = 10
354
+ b = [10] # wrap in a value of mutable type list
355
+ add_one(a, b)
356
+
357
+ print(f"a:{a} b:{b[0]}")
358
+ ```
359
+ ![wap_int.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/wrap_int.png)
360
+ ```
361
+ a:10 b:11
362
+ ```
363
+ Calling `add_one()` does not effect the `int` value of `a` but does effect the `int` value of `b` because it's wrapped in a mutable container.
364
+
365
+ ## Exercises ##
366
+
368
367
  Now is a good time to practice the Python Data Model. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
369
368
 
370
369
  ## Block ##
@@ -712,6 +711,12 @@ Different aspects of memory_graph can be configured. The default configuration c
712
711
  - ***mg.config.max_missing_edges*** : int
713
712
  - Maximum number of missing edges that are shown with default value 2. Dashed references are used to indicate that there are more references to a node than are shown.
714
713
 
714
+ - ***mg.config.fontname*** : str
715
+ - The font used in the graph, default 'Courier' (as widely available monospace).
716
+
717
+ - ***mg.config.fontsize*** : str
718
+ - The font size used in the graph, default '14'.
719
+
715
720
 
716
721
  ## Simplified Graph ##
717
722
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a` won’t affect `b`) so will never result in bugs.
@@ -317,9 +317,33 @@ In the printed output only `a` is changed as a result of the function call:
317
317
  ```
318
318
  a:[4, 3, 2, 1] b:(4, 3, 2) c:[4, 3, 2]
319
319
  ```
320
-
321
320
  This is because `b` is of immutable type 'tuple' so its value gets copied automatically when it is changed. And because the function is called with a copy of `c`, its original value is not changed by the function. The value of variable `a` is the only value of mutable type that is shared between the root stack frame **'0: \<module>'** and the **'1: add_one'** stack frame of the function so only that variable is affected as a result of the function call. The other changes remain confined to the local variables of the ```add_one()``` function.
322
321
 
322
+ ## Function Call That Changes 'int' Value ##
323
+ Even though `int` is an immutable type, so an `int` value can not be changed by directly passing it to a function, we can still change it by wrapping it in a mutable container.
324
+
325
+ ```python
326
+ import memory_graph as mg
327
+
328
+ def add_one(a, b):
329
+ a += 1 # change remains confined to 'a' in the add_one function
330
+ b[0] += 1 # change also effects 'b' outside of the add_one function
331
+ mg.show(mg.stack())
332
+
333
+ a = 10
334
+ b = [10] # wrap in a value of mutable type list
335
+ add_one(a, b)
336
+
337
+ print(f"a:{a} b:{b[0]}")
338
+ ```
339
+ ![wap_int.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/wrap_int.png)
340
+ ```
341
+ a:10 b:11
342
+ ```
343
+ Calling `add_one()` does not effect the `int` value of `a` but does effect the `int` value of `b` because it's wrapped in a mutable container.
344
+
345
+ ## Exercises ##
346
+
323
347
  Now is a good time to practice the Python Data Model. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
324
348
 
325
349
  ## Block ##
@@ -667,6 +691,12 @@ Different aspects of memory_graph can be configured. The default configuration c
667
691
  - ***mg.config.max_missing_edges*** : int
668
692
  - Maximum number of missing edges that are shown with default value 2. Dashed references are used to indicate that there are more references to a node than are shown.
669
693
 
694
+ - ***mg.config.fontname*** : str
695
+ - The font used in the graph, default 'Courier' (as widely available monospace).
696
+
697
+ - ***mg.config.fontsize*** : str
698
+ - The font size used in the graph, default '14'.
699
+
670
700
 
671
701
  ## Simplified Graph ##
672
702
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a` won’t affect `b`) so will never result in bugs.
Binary file
Binary file
Binary file
Binary file
@@ -16,6 +16,7 @@ python name_rebinding.py
16
16
 
17
17
  # call stack
18
18
  python add_one.py
19
+ python wrap_int.py
19
20
  python factorial.py
20
21
  bash create_gif.sh factorial -d
21
22
  python binary.py
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,16 @@
1
+ # This file is part of memory_graph.
2
+ # Copyright (c) 2023, Bas Terwijn.
3
+ # SPDX-License-Identifier: BSD-2-Clause
4
+
5
+ import memory_graph as mg
6
+
7
+ def add_one(a, b):
8
+ a += 1
9
+ b[0] += 1
10
+ mg.render( mg.stack(), "wrap_int.png")
11
+
12
+ a = 10
13
+ b = [10]
14
+
15
+ add_one(a, b)
16
+ print(f"a:{a} b:{b[0]}")
@@ -2,7 +2,7 @@
2
2
  # Copyright (c) 2023, Bas Terwijn.
3
3
  # SPDX-License-Identifier: BSD-2-Clause
4
4
 
5
- __version__ = "0.3.55"
5
+ __version__ = "0.3.57"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -46,3 +46,6 @@ graph_cut_symbol = None
46
46
  max_missing_edges = None
47
47
 
48
48
  type_to_depth = { }
49
+
50
+ fontname = 'Courier'
51
+ fontsize = '14'
@@ -129,5 +129,8 @@ def reset():
129
129
  """ Maximum number of missing edges that are shown. """
130
130
  config.max_missing_edges = 2
131
131
 
132
+ """ Font name and size used in the graph. """
133
+ config.fontname = 'Courier'
134
+ config.fontsize = '14'
132
135
 
133
136
  reset()
@@ -257,9 +257,9 @@ def memory_to_nodes(data):
257
257
  id_to_slices = add_missing_edges(nodes, id_to_slices, config.max_missing_edges)
258
258
  #print('id_to_slices:',id_to_slices)
259
259
  embed_keys_in_key_value_nodes(nodes, nodes_key_value, id_to_slices)
260
- graphviz_graph_attr = {}
261
- graphviz_node_attr = {'shape':'plaintext'}
262
- graphviz_edge_attr = {}
260
+ graphviz_graph_attr = {'fontname': config.fontname, 'fontsize': config.fontsize}
261
+ graphviz_node_attr = {'fontname': config.fontname, 'fontsize': config.fontsize, 'shape': 'plaintext'}
262
+ graphviz_edge_attr = {'fontname': config.fontname, 'fontsize': config.fontsize}
263
263
  graphviz_graph=graphviz.Digraph('memory_graph',
264
264
  graph_attr=graphviz_graph_attr,
265
265
  node_attr=graphviz_node_attr,
@@ -20,7 +20,7 @@ def is_function(obj):
20
20
 
21
21
  def filter_dict(dictionary):
22
22
  """ Filters out the unwanted dict attributes. """
23
- if '__name__' in dictionary: # only filter stack frames, for example locals()
23
+ if '__name__' in dictionary: # filter stack frames in global scope
24
24
  return [
25
25
  (k,v) for k, v in dictionary.items() if
26
26
  not (type(k) is str and k.startswith('__')) and
@@ -1,34 +1,9 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.55
3
+ Version: 0.3.57
4
4
  Summary: Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy.
5
5
  Author-email: Bas Terwijn <bterwijn@gmail.com>
6
- License: BSD 2-Clause License
7
-
8
- Copyright (c) 2017, pyexample
9
- All rights reserved.
10
-
11
- Redistribution and use in source and binary forms, with or without
12
- modification, are permitted provided that the following conditions are met:
13
-
14
- * Redistributions of source code must retain the above copyright notice, this
15
- list of conditions and the following disclaimer.
16
-
17
- * Redistributions in binary form must reproduce the above copyright notice,
18
- this list of conditions and the following disclaimer in the documentation
19
- and/or other materials provided with the distribution.
20
-
21
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
-
6
+ License-Expression: BSD-2-Clause
32
7
  Project-URL: Homepage, https://github.com/bterwijn/memory_graph
33
8
  Project-URL: Repository, https://github.com/bterwijn/memory_graph.git
34
9
  Classifier: Development Status :: 4 - Beta
@@ -362,9 +337,33 @@ In the printed output only `a` is changed as a result of the function call:
362
337
  ```
363
338
  a:[4, 3, 2, 1] b:(4, 3, 2) c:[4, 3, 2]
364
339
  ```
365
-
366
340
  This is because `b` is of immutable type 'tuple' so its value gets copied automatically when it is changed. And because the function is called with a copy of `c`, its original value is not changed by the function. The value of variable `a` is the only value of mutable type that is shared between the root stack frame **'0: \<module>'** and the **'1: add_one'** stack frame of the function so only that variable is affected as a result of the function call. The other changes remain confined to the local variables of the ```add_one()``` function.
367
341
 
342
+ ## Function Call That Changes 'int' Value ##
343
+ Even though `int` is an immutable type, so an `int` value can not be changed by directly passing it to a function, we can still change it by wrapping it in a mutable container.
344
+
345
+ ```python
346
+ import memory_graph as mg
347
+
348
+ def add_one(a, b):
349
+ a += 1 # change remains confined to 'a' in the add_one function
350
+ b[0] += 1 # change also effects 'b' outside of the add_one function
351
+ mg.show(mg.stack())
352
+
353
+ a = 10
354
+ b = [10] # wrap in a value of mutable type list
355
+ add_one(a, b)
356
+
357
+ print(f"a:{a} b:{b[0]}")
358
+ ```
359
+ ![wap_int.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/wrap_int.png)
360
+ ```
361
+ a:10 b:11
362
+ ```
363
+ Calling `add_one()` does not effect the `int` value of `a` but does effect the `int` value of `b` because it's wrapped in a mutable container.
364
+
365
+ ## Exercises ##
366
+
368
367
  Now is a good time to practice the Python Data Model. Here are [some exercises](https://github.com/bterwijn/memory_graph_videos/blob/main/exercises/exercises.md) on references, mutability, copies, and function calls.
369
368
 
370
369
  ## Block ##
@@ -712,6 +711,12 @@ Different aspects of memory_graph can be configured. The default configuration c
712
711
  - ***mg.config.max_missing_edges*** : int
713
712
  - Maximum number of missing edges that are shown with default value 2. Dashed references are used to indicate that there are more references to a node than are shown.
714
713
 
714
+ - ***mg.config.fontname*** : str
715
+ - The font used in the graph, default 'Courier' (as widely available monospace).
716
+
717
+ - ***mg.config.fontsize*** : str
718
+ - The font size used in the graph, default '14'.
719
+
715
720
 
716
721
  ## Simplified Graph ##
717
722
  Memory_graph simplifies the visualization (and the viewer's mental model) by **not** showing separate nodes for immutable types like `bool`, `int`, `float`, `complex`, and `str` by default. This simplification can sometimes be slightly misleading. As in the example below, after a shallow copy, lists `a` and `b` technically share their `int` values, but the graph makes it appear as though `a` and `b` each have their own copies. However, since `int` is immutable, this simplification will never lead to unexpected changes (changing `a` won’t affect `b`) so will never result in bugs.
@@ -74,6 +74,8 @@ images/rebinding1.png
74
74
  images/rebinding2.png
75
75
  images/uva.png
76
76
  images/vscode_copying.gif
77
+ images/wrap_int.png
78
+ images/wrap_int.py
77
79
  memory_graph/__init__.py
78
80
  memory_graph/call_stack.py
79
81
  memory_graph/config.py
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "memory_graph"
7
- version = "0.3.55"
7
+ version = "0.3.57"
8
8
  description = "Teaching tool and debugging aid in context of references, mutable data types, and shallow and deep copy."
9
9
  authors = [
10
10
  {name = "Bas Terwijn", email = "bterwijn@gmail.com"}
11
11
  ]
12
- #license = { text = "BSD-2-Clause" } # needed for python <=3.8
13
- license = { file = "LICENSE.txt" }
12
+ license = "BSD-2-Clause"
13
+ license-files = ["LICENSE.txt"]
14
14
  readme = "README.md"
15
15
  requires-python = ">=3.7"
16
16
  classifiers = [
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
File without changes
File without changes
File without changes
File without changes