memory-graph 0.3.94__tar.gz → 0.3.95__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 (43) hide show
  1. {memory_graph-0.3.94 → memory_graph-0.3.95}/PKG-INFO +12 -8
  2. {memory_graph-0.3.94 → memory_graph-0.3.95}/README.md +11 -7
  3. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/__init__.py +2 -2
  4. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/config_default.py +2 -1
  5. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/memory_to_nodes.py +1 -1
  6. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/utils.py +32 -7
  7. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph.egg-info/PKG-INFO +12 -8
  8. {memory_graph-0.3.94 → memory_graph-0.3.95}/pyproject.toml +1 -1
  9. {memory_graph-0.3.94 → memory_graph-0.3.95}/LICENSE.txt +0 -0
  10. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/call_stack.py +0 -0
  11. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/config.py +0 -0
  12. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/config_helpers.py +0 -0
  13. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/extension_numpy.py +0 -0
  14. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/extension_pandas.py +0 -0
  15. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/extension_polars.py +0 -0
  16. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/extension_sqlite3.py +0 -0
  17. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/extension_torch.py +0 -0
  18. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/html_table.py +0 -0
  19. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/list_view.py +0 -0
  20. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/node_base.py +0 -0
  21. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/node_key_value.py +0 -0
  22. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/node_leaf.py +0 -0
  23. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/node_linear.py +0 -0
  24. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/node_table.py +0 -0
  25. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/sequence.py +0 -0
  26. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/slicer.py +0 -0
  27. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/slices.py +0 -0
  28. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/slices_iterator.py +0 -0
  29. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/slices_table_iterator.py +0 -0
  30. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test.py +0 -0
  31. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_max_graph_depth.py +0 -0
  32. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_memory_graph.py +0 -0
  33. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_memory_to_nodes.py +0 -0
  34. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_sequence.py +0 -0
  35. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_slicer.py +0 -0
  36. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_slices.py +0 -0
  37. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph/test_slices_iterator.py +0 -0
  38. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph.egg-info/SOURCES.txt +0 -0
  39. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph.egg-info/dependency_links.txt +0 -0
  40. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph.egg-info/requires.txt +0 -0
  41. {memory_graph-0.3.94 → memory_graph-0.3.95}/memory_graph.egg-info/top_level.txt +0 -0
  42. {memory_graph-0.3.94 → memory_graph-0.3.95}/setup.cfg +0 -0
  43. {memory_graph-0.3.94 → memory_graph-0.3.95}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.94
3
+ Version: 0.3.95
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
6
  License-Expression: BSD-2-Clause
@@ -1145,20 +1145,20 @@ Different aspects of memory_graph can be configured. The default configuration c
1145
1145
 
1146
1146
  ## Functions ##
1147
1147
 
1148
- - **mg.layout(horizontal: bool = None)**
1149
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1150
-
1151
1148
  - **mg.dark_mode(b: bool = None)**
1152
1149
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1153
1150
 
1151
+ - **mg.layout(horizontal: bool = None)**
1152
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1153
+
1154
1154
  - **mg.transparent_background(b: bool = None)**
1155
1155
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1156
1156
 
1157
- - **mg.spline(splines: str = None)**
1158
- - Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
1157
+ - **mg.splines(splines: str = None)**
1158
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1159
1159
 
1160
1160
  - **mg.ranksep(ranksep: str = None)**
1161
- - Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
1161
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1162
1162
 
1163
1163
  ## Simplified Graph ##
1164
1164
  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`'s ints won’t affect `b`) so will never result in bugs.
@@ -1430,7 +1430,7 @@ mg.show(locals())
1430
1430
 
1431
1431
  ### Images
1432
1432
 
1433
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1433
+ Including the `<IMG>` tag that allows showing local image files only.
1434
1434
 
1435
1435
  ```python
1436
1436
  import memory_graph as mg
@@ -1452,6 +1452,10 @@ mg.show(locals())
1452
1452
  ```
1453
1453
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1454
1454
 
1455
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1456
+
1457
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1458
+
1455
1459
  ## Collapse Type ##
1456
1460
 
1457
1461
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -1125,20 +1125,20 @@ Different aspects of memory_graph can be configured. The default configuration c
1125
1125
 
1126
1126
  ## Functions ##
1127
1127
 
1128
- - **mg.layout(horizontal: bool = None)**
1129
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1130
-
1131
1128
  - **mg.dark_mode(b: bool = None)**
1132
1129
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1133
1130
 
1131
+ - **mg.layout(horizontal: bool = None)**
1132
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1133
+
1134
1134
  - **mg.transparent_background(b: bool = None)**
1135
1135
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1136
1136
 
1137
- - **mg.spline(splines: str = None)**
1138
- - Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
1137
+ - **mg.splines(splines: str = None)**
1138
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1139
1139
 
1140
1140
  - **mg.ranksep(ranksep: str = None)**
1141
- - Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
1141
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1142
1142
 
1143
1143
  ## Simplified Graph ##
1144
1144
  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`'s ints won’t affect `b`) so will never result in bugs.
@@ -1410,7 +1410,7 @@ mg.show(locals())
1410
1410
 
1411
1411
  ### Images
1412
1412
 
1413
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1413
+ Including the `<IMG>` tag that allows showing local image files only.
1414
1414
 
1415
1415
  ```python
1416
1416
  import memory_graph as mg
@@ -1432,6 +1432,10 @@ mg.show(locals())
1432
1432
  ```
1433
1433
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1434
1434
 
1435
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1436
+
1437
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1438
+
1435
1439
  ## Collapse Type ##
1436
1440
 
1437
1441
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -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.94"
5
+ __version__ = "0.3.95"
6
6
  __author__ = 'Bas Terwijn'
7
7
 
8
8
  import memory_graph.memory_to_nodes as memory_to_nodes
@@ -26,7 +26,7 @@ if not hasattr(builtins, "mg"):
26
26
  builtins.mg = mg
27
27
 
28
28
  # re-exports for shorter names
29
- from .config_default import layout, spline, ranksep, dark_mode, transparent_background, set_colors
29
+ from .config_default import layout, spline, splines, ranksep, dark_mode, transparent_background, set_colors
30
30
  from .slicer import Slicer
31
31
  from .node_leaf import Node_Leaf
32
32
  from .node_linear import Node_Linear
@@ -115,9 +115,10 @@ def layout(horizontal = None):
115
115
  else:
116
116
  config.horizontal = horizontal
117
117
 
118
- def spline(splines = None):
118
+ def splines(splines = None):
119
119
  """ Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default. """
120
120
  config.splines = 'spline' if splines is None else splines
121
+ spline = splines # alias for backward compatibility
121
122
 
122
123
  def ranksep(ranksep = None):
123
124
  """ Set the graphviz 'ranksep' attribute (separation between ranks in inches), None restores the default. """
@@ -26,7 +26,7 @@ def read_nodes(data):
26
26
  if (to_node):
27
27
  return to_node(data)
28
28
  elif utils.has_dict_attributes(data): # for user defined classes
29
- return Node_Key_Value(data, utils.filter_dict(utils.get_dict_attributes(data)) )
29
+ return Node_Key_Value(data, utils.filter_class_dict(utils.get_dict_attributes(data)) )
30
30
  elif utils.is_finite_iterable(data): # for lists, tuples, sets, ...
31
31
  return Node_Linear(data, data)
32
32
  else:
@@ -133,19 +133,44 @@ def is_not_state(obj):
133
133
  'method-wrapper',
134
134
  }
135
135
 
136
+ def is_own_function_definition(key, value):
137
+ """ Returns 'True' if 'value' is a function/method defined under its own name 'key', e.g. a
138
+ module-level 'def add(): ...' binds the name 'add' to a function whose '__name__' is also
139
+ 'add'. Such a binding is just a normal function definition, not state. A variable that
140
+ references a function under a different name (e.g. 'a = add') is still considered state. """
141
+ if not isinstance(value, (types.FunctionType, types.MethodType,
142
+ types.BuiltinFunctionType, types.BuiltinMethodType)):
143
+ return False
144
+ return getattr(value, '__name__', None) == key
145
+
136
146
  def filter_dict(dictionary):
137
- """ Filters out the unwanted dict attributes. """
138
- if '__name__' in dictionary:
139
- return [ # filter classes and modules, no non-state allowed as values
147
+ """ Filters out the unwanted dunder attributes of a plain 'dictionary' or stack frame
148
+ (locals()/globals()). Non-state values like functions are allowed since a dictionary or
149
+ stack frame is considered state, e.g. a variable can point to a function. Modules are
150
+ assumed to have no state and are never shown. If 'dictionary' looks like a module namespace
151
+ (has a '__name__' key, e.g. the global '<module>' stack frame) functions bound under their
152
+ own name are also filtered out, since those are normal function definitions rather than
153
+ variables (state) referencing a function. """
154
+ is_module_namespace = '__name__' in dictionary
155
+ return [
140
156
  (k,v) for k, v in dictionary.items() if
141
157
  not (type(k) is str and k.startswith('__')) and
142
158
  not isinstance(v,types.ModuleType) and
159
+ not (is_module_namespace and is_own_function_definition(k, v))
160
+ ]
161
+
162
+ def filter_class_dict(dictionary):
163
+ """ Filters out the unwanted attributes of a class' or module's '__dict__'. If 'dictionary'
164
+ looks like a class or module namespace (has a '__name__' key) then non-state values such as
165
+ functions and methods are also filtered out, since there can be too many of them to show and
166
+ they are not considered state. Otherwise (e.g. a plain instance's '__dict__') behaves like
167
+ 'filter_dict'. """
168
+ if '__name__' in dictionary:
169
+ return [ # filter classes and modules, no non-state allowed as values
170
+ (k,v) for k, v in filter_dict(dictionary) if
143
171
  not is_not_state(v)
144
172
  ]
145
- return [ # filter dictionaries, non-state allowed as values
146
- (k,v) for k, v in dictionary.items() if
147
- not (type(k) is str and k.startswith('__'))
148
- ]
173
+ return filter_dict(dictionary)
149
174
 
150
175
  def filter_type_attributes(tuples):
151
176
  """ Filters out the unwanted type attributes (class/static methods). """
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memory_graph
3
- Version: 0.3.94
3
+ Version: 0.3.95
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
6
  License-Expression: BSD-2-Clause
@@ -1145,20 +1145,20 @@ Different aspects of memory_graph can be configured. The default configuration c
1145
1145
 
1146
1146
  ## Functions ##
1147
1147
 
1148
- - **mg.layout(horizontal: bool = None)**
1149
- - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1150
-
1151
1148
  - **mg.dark_mode(b: bool = None)**
1152
1149
  - Set dark mode to 'True' or 'False', or 'None' to toggle.
1153
1150
 
1151
+ - **mg.layout(horizontal: bool = None)**
1152
+ - Set graph layout to 'True' for horizontal, 'False' for vertical, or 'None' to toggle.
1153
+
1154
1154
  - **mg.transparent_background(b: bool = None)**
1155
1155
  - Set transparent background to 'True' or 'False', or 'None' to toggle.
1156
1156
 
1157
- - **mg.spline(splines: str = None)**
1158
- - Set the graphviz 'splines' attribute (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), None restores the default.
1157
+ - **mg.splines(splines: str = None)**
1158
+ - Set the graphviz [splines attribute](https://graphviz.org/docs/attrs/splines/) (e.g. 'polyline', 'ortho', 'curved', 'line', 'spline'), 'None' restores the default.
1159
1159
 
1160
1160
  - **mg.ranksep(ranksep: str = None)**
1161
- - Set the graphviz 'ranksep' attribute (separation between ranks, say "2.0"), None restores the default.
1161
+ - Set the graphviz [ranksep attribute](https://graphviz.org/docs/attrs/ranksep/) (separation between ranks, say "2.0"), 'None' restores the default.
1162
1162
 
1163
1163
  ## Simplified Graph ##
1164
1164
  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`'s ints won’t affect `b`) so will never result in bugs.
@@ -1430,7 +1430,7 @@ mg.show(locals())
1430
1430
 
1431
1431
  ### Images
1432
1432
 
1433
- Including the `<IMG>` tag that allows for showing local image files only, but that currently doesn't work in the Memory Graph Web Debugger, that uses 'Viz.js' for graph rendering, unfortunately.
1433
+ Including the `<IMG>` tag that allows showing local image files only.
1434
1434
 
1435
1435
  ```python
1436
1436
  import memory_graph as mg
@@ -1452,6 +1452,10 @@ mg.show(locals())
1452
1452
  ```
1453
1453
  ![html_str_image.png](https://raw.githubusercontent.com/bterwijn/memory_graph/main/images/html_str_image.png)
1454
1454
 
1455
+ Or see it in the [Memory Graph Web Debugger](https://memory-graph.com/#micropip=matplotlib&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/matplotlib.py&timestep=0.1&play).
1456
+
1457
+ As Matplotlib can be slow, consider [creating your own SVG file](https://memory-graph.com/#codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/plot_svg.py&timestep=0.001&play&play_button=step_over) for speed, or [use Pillow to create images](https://memory-graph.com/#micropip=pillow&codeurl=https://raw.githubusercontent.com/bterwijn/memory_graph/refs/heads/main/src/bounce_circles.py&breakpoints=26&timestep=0&play&play_button=continue), or use many other ways.
1458
+
1455
1459
  ## Collapse Type ##
1456
1460
 
1457
1461
  Sometimes a type has too many attributes or too many child nodes in the graph for it to stay readable. We use type 'MyClass' as an example here:
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "memory_graph"
7
- version = "0.3.94"
7
+ version = "0.3.95"
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"}
File without changes
File without changes
File without changes