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.
- {memory_graph-0.3.55/memory_graph.egg-info → memory_graph-0.3.57}/PKG-INFO +33 -28
- {memory_graph-0.3.55 → memory_graph-0.3.57}/README.md +31 -1
- memory_graph-0.3.57/images/add_one.png +0 -0
- memory_graph-0.3.57/images/avltree_key_value.png +0 -0
- memory_graph-0.3.57/images/avltree_leaf.png +0 -0
- memory_graph-0.3.57/images/avltree_linear.png +0 -0
- memory_graph-0.3.57/images/avltree_table.png +0 -0
- memory_graph-0.3.57/images/bin_search.png +0 -0
- memory_graph-0.3.57/images/bin_search_linear.png +0 -0
- memory_graph-0.3.57/images/bin_tree.png +0 -0
- memory_graph-0.3.57/images/binary.gif +0 -0
- memory_graph-0.3.57/images/copy_immutable.png +0 -0
- memory_graph-0.3.57/images/copy_method.png +0 -0
- memory_graph-0.3.57/images/copy_mix.png +0 -0
- memory_graph-0.3.57/images/copy_mutable.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/create_images.sh +1 -0
- memory_graph-0.3.57/images/debugging.gif +0 -0
- memory_graph-0.3.57/images/embedded1.png +0 -0
- memory_graph-0.3.57/images/embedded2.png +0 -0
- memory_graph-0.3.57/images/extension_numpy.png +0 -0
- memory_graph-0.3.57/images/extension_pandas.png +0 -0
- memory_graph-0.3.57/images/factorial.gif +0 -0
- memory_graph-0.3.57/images/hash_set.png +0 -0
- memory_graph-0.3.57/images/hidden_edges.png +0 -0
- memory_graph-0.3.57/images/immutable1.png +0 -0
- memory_graph-0.3.57/images/immutable2.png +0 -0
- memory_graph-0.3.57/images/introspect_depth.png +0 -0
- memory_graph-0.3.57/images/linked_list.png +0 -0
- memory_graph-0.3.57/images/many_types.png +0 -0
- memory_graph-0.3.57/images/mutable1.png +0 -0
- memory_graph-0.3.57/images/mutable2.png +0 -0
- memory_graph-0.3.57/images/power_set.gif +0 -0
- memory_graph-0.3.57/images/rebinding1.png +0 -0
- memory_graph-0.3.57/images/rebinding2.png +0 -0
- memory_graph-0.3.57/images/wrap_int.png +0 -0
- memory_graph-0.3.57/images/wrap_int.py +16 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/__init__.py +1 -1
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config.py +3 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config_default.py +3 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/memory_to_nodes.py +3 -3
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/utils.py +1 -1
- {memory_graph-0.3.55 → memory_graph-0.3.57/memory_graph.egg-info}/PKG-INFO +33 -28
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/SOURCES.txt +2 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/pyproject.toml +3 -3
- memory_graph-0.3.55/images/add_one.png +0 -0
- memory_graph-0.3.55/images/avltree_key_value.png +0 -0
- memory_graph-0.3.55/images/avltree_leaf.png +0 -0
- memory_graph-0.3.55/images/avltree_linear.png +0 -0
- memory_graph-0.3.55/images/avltree_table.png +0 -0
- memory_graph-0.3.55/images/bin_search.png +0 -0
- memory_graph-0.3.55/images/bin_search_linear.png +0 -0
- memory_graph-0.3.55/images/bin_tree.png +0 -0
- memory_graph-0.3.55/images/binary.gif +0 -0
- memory_graph-0.3.55/images/copy_immutable.png +0 -0
- memory_graph-0.3.55/images/copy_method.png +0 -0
- memory_graph-0.3.55/images/copy_mix.png +0 -0
- memory_graph-0.3.55/images/copy_mutable.png +0 -0
- memory_graph-0.3.55/images/debugging.gif +0 -0
- memory_graph-0.3.55/images/embedded1.png +0 -0
- memory_graph-0.3.55/images/embedded2.png +0 -0
- memory_graph-0.3.55/images/extension_numpy.png +0 -0
- memory_graph-0.3.55/images/extension_pandas.png +0 -0
- memory_graph-0.3.55/images/factorial.gif +0 -0
- memory_graph-0.3.55/images/hash_set.png +0 -0
- memory_graph-0.3.55/images/hidden_edges.png +0 -0
- memory_graph-0.3.55/images/immutable1.png +0 -0
- memory_graph-0.3.55/images/immutable2.png +0 -0
- memory_graph-0.3.55/images/introspect_depth.png +0 -0
- memory_graph-0.3.55/images/linked_list.png +0 -0
- memory_graph-0.3.55/images/many_types.png +0 -0
- memory_graph-0.3.55/images/mutable1.png +0 -0
- memory_graph-0.3.55/images/mutable2.png +0 -0
- memory_graph-0.3.55/images/power_set.gif +0 -0
- memory_graph-0.3.55/images/rebinding1.png +0 -0
- memory_graph-0.3.55/images/rebinding2.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/LICENSE.txt +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/MANIFEST.in +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/add_one.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree_dir.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/avltree_fail.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_search.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_tree.gif +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/bin_tree.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/binary.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/colab_example.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_immutable.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_method.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_mix.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/copy_mutable.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/create_gif.sh +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/debug_vscode.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/debugging.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_numpy.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_pandas.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_torch.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/extension_torch.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/factorial.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hash_set.gif +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hash_set.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/hidden_edges.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/immutable.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/introspect_depth.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/ipython.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/jupyter_example.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/linked_list.gif +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/linked_list.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/many_types.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/marimo_example.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/memory_graph_web_debugger.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/mutable.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/name_rebinding.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/not_node_types.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/power_set.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/uva.png +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/images/vscode_copying.gif +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/call_stack.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/config_helpers.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_numpy.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_pandas.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/extension_torch.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/html_table.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/list_view.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_base.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_key_value.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_leaf.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_linear.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/node_table.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/sequence.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slicer.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices_iterator.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/slices_table_iterator.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_max_graph_depth.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_memory_graph.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_memory_to_nodes.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_sequence.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slicer.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slices.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph/test_slices_iterator.py +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/dependency_links.txt +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/requires.txt +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/memory_graph.egg-info/top_level.txt +0 -0
- {memory_graph-0.3.55 → memory_graph-0.3.57}/setup.cfg +0 -0
- {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.
|
|
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
|
|
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
|
+

|
|
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
|
+

|
|
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
|
|
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
|
|
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]}")
|
|
@@ -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: #
|
|
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.
|
|
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
|
|
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
|
+

|
|
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.
|
|
@@ -4,13 +4,13 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "memory_graph"
|
|
7
|
-
version = "0.3.
|
|
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
|
-
|
|
13
|
-
license =
|
|
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
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|