memorymanagement 1.2.0__tar.gz → 1.2.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: memorymanagement
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Adds support for memory management
5
5
  Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
@@ -6,48 +6,58 @@ class Cleaner:
6
6
  """
7
7
  Class for references management. It keeps track of the names of the global variables to be deleted and deletes them when ordered.
8
8
 
9
- The cleaning process only deletes the flagged references to objects, but doesn't directly force the garbage collector to destroy the objects they are pointing to.\n
10
- ---
9
+ The cleaning process only deletes the flagged references to objects, but doesn't directly force the garbage collector to destroy the objects they are pointing to.
10
+
11
11
  ## WARNING
12
12
  THERE CAN ONLY BE **ONE** CLEANER OBJECT.\n
13
- Initializing a new one will delete all global references to the previous one.\n
14
- ---
15
- Attributes:
16
- _not_delete (`list[str]`, Hidden): List of variables to never delete from memory. These cannot be included in the process even if ordered so.\n
17
- These mainly are variables needed for the system to work and imports.
18
- _excluded (`list[str]`, Hidden): List of variables excluded from the memory cleaning that can be included again if desired.
19
- _flagged (`list[str]`, Hidden): List of variables to erase from memory. Variables can be put in and/or taken out through methods.
20
- _name (`str`, Hidden): Name of the variable referencing the `Cleaner` object. Only for internal purposes.
21
- ---
22
- \n## Methods
23
- :update: *`MethodType`*
24
- Updates the list of variables to erase from memory including all the new variables global variables not manually excluded.\n
25
- It also allows to incorporate previously excluded variables.
26
- :exclude: *`MethodType`*
27
- Allows you to exclude variables from the cleaning process without need to use the `instance.update()` method.
28
- :include: *`MethodType`*
29
- Allows you to include variables in the cleaning process without need to use the `instance.update()` method.
30
- :clean: *`MethodType`*
31
- Erases all the flagged references from memory.
32
- ---
33
- \n## Properties
34
- :not_delete: *`MethodType`*, *Getter*
35
- Returns the list of variables that shouldn't be deleted and can't be included in the cleaning process.
36
- :excluded: *`MethodType`*, *Getter*
37
- Returns the list of variables excluded from the cleaning process but can be included again if ordered.
38
- :flagged: *`MethodType`*, *Getter*
39
- Returns the list of variables to be erased from memory.
40
- None of this properties has setter or deleter. Those lists can only be manipulated through the class methods.
13
+ Initializing a new one will delete all global references to the previous one.
14
+
15
+ Attributes
16
+ ----------
17
+ _not_delete : `list[str]`, Hidden
18
+ List of variables to never delete from memory. These cannot be included in the process even if ordered so.
19
+ These mainly are imports and variables needed for the system to work.
20
+ _excluded : `list[str]`, Hidden
21
+ List of variables excluded from the memory cleaning that can be included again if desired.
22
+ _flagged : `list[str]`, Hidden
23
+ List of variables to erase from memory. Variables can be put in and/or taken out through methods.
24
+ _name : `str`, Hidden
25
+ Name of the variable referencing the `Cleaner` object. Only for internal purposes.
26
+
27
+ Methods
28
+ -------
29
+ **update**
30
+ Updates the list of variables to erase from memory including all the new variables global variables not manually excluded. It also allows to incorporate previously excluded variables.
31
+ **exclude**
32
+ Allows you to exclude variables from the cleaning process without need to use the `instance.update()` method.
33
+ **include**
34
+ Allows you to include variables in the cleaning process without need to use the `instance.update()` method.
35
+ **clean**
36
+ Erases all the flagged references from memory.
37
+
38
+ Properties
39
+ ----------
40
+ **not_delete**
41
+ Returns the list of variables that shouldn't be deleted and can't be included in the cleaning process.
42
+ **excluded**
43
+ Returns the list of variables excluded from the cleaning process but can be included again if ordered.
44
+ **flagged**
45
+ Returns the list of variables to be erased from memory.
46
+ None of this properties has setter or deleter. Those lists can only be manipulated through the class methods.
41
47
  """
42
48
  def __init__(self,not_delete:list[str]|None=None,excluded:list[str]=[],flagged:list[str]=[]):
43
49
  """
44
50
  Initializes the class instance.\n
45
- It is recommended to initialize the instance right after all global imports at the beggining of the program so no argument is needed.\n
46
- ---
47
- Arguments:
48
- not_delete (`list[str]`, Optional): List of variables to never be deleted. It takes the list of global variables of the main module by default.
49
- excluded (`list[str]`, Optional): List of variables to be excluded from the memory cleaning process. Empty list by default.
50
- flagged (`list[str]`, Optional): List of variables to be erased from memory. Empty list by default.
51
+ It is recommended to initialize the instance right after all global imports at the beggining of the program so no argument is needed.
52
+
53
+ Arguments
54
+ ---------
55
+ not_delete : `list[str]`, Optional
56
+ List of variables to never be deleted. It takes the list of global variables of the main module by default.
57
+ excluded : `list[str]`, Optional
58
+ List of variables to be excluded from the memory cleaning process. Empty list by default.
59
+ flagged : `list[str]`, Optional
60
+ List of variables to be erased from memory. Empty list by default.
51
61
  """
52
62
  if not not_delete:
53
63
  not_delete=list(vars(modules["__main__"]))
@@ -60,14 +70,16 @@ class Cleaner:
60
70
  self._name=None
61
71
  def update(self,exclude:str|list[str]|tuple[str]|None=None,include:str|list[str]|tuple[str]|None=None):
62
72
  """
63
- Flags all the new global variables' references that were not manually excluded here or before. You can also include previously excluded references.
73
+ Flags all the new global variables' references that were not manually excluded here or before.
74
+ You can also include previously excluded references.
64
75
 
65
- ---
66
- Arguments:
67
- exclude (`str`|`list[str]`|`tuple[str]`|`None`, Optional): Allows you to exclude a single (`str`) or multiple (`list` or `tuple`) variables.
68
- `None` by default.
69
- include (`str`|`list[str]`|`tuple[str]`|`None`, Optional): Allows you to include a single (`str`) or multiple (`list` or `tuple`) variables.
70
- `None` by default.
76
+ Arguments
77
+ ---------
78
+ exclude : `str`|`list[str]`|`tuple[str]`|`None`, Optional
79
+ Allows you to exclude a single (`str`) or multiple (`list` or `tuple`) variables.
80
+ `None` by default.
81
+ include : `str`|`list[str]`|`tuple[str]`|`None`, Optional
82
+ Allows you to include a single (`str`) or multiple (`list` or `tuple`) variables. `None` by default.
71
83
  """
72
84
  if exclude:
73
85
  if isinstance(exclude,str):
@@ -88,6 +100,8 @@ class Cleaner:
88
100
  self._name=key
89
101
  self._not_delete.append(self._name)
90
102
  break
103
+ else:
104
+ self._name=None
91
105
  if not self._name:
92
106
  raise ReferenceError("'Cleaner' object is not referenced")
93
107
  elif self._name not in self._not_delete:
@@ -103,9 +117,10 @@ class Cleaner:
103
117
  """
104
118
  Allows to exclude the desired references from the cleaning process.
105
119
 
106
- ---
107
- Arguments:
108
- *exclude (`str`): Stream of references to be excluded.
120
+ Arguments
121
+ ---------
122
+ exclude : `tuple[str]`
123
+ Stream of references to be excluded.
109
124
  """
110
125
  for var in exclude:
111
126
  while var in self._flagged:
@@ -116,9 +131,10 @@ class Cleaner:
116
131
  """
117
132
  Allows to include the desired references (previously excluded) in the cleaning process.
118
133
 
119
- ---
120
- Arguments:
121
- *include (`str`): Stream of references to be included.
134
+ Arguments
135
+ ---------
136
+ include : `tuple[str]`
137
+ Stream of references to be included.
122
138
  """
123
139
  for var in include:
124
140
  if var not in self._flagged:
@@ -127,7 +143,8 @@ class Cleaner:
127
143
  self._excluded.remove(var)
128
144
  def clean(self):
129
145
  """
130
- Culminates the cleaning process. Erases all the flagged references.
146
+ Culminates the cleaning process.
147
+ Erases all the flagged references.
131
148
  """
132
149
  for var in self._flagged:
133
150
  if var in list(vars(modules["__main__"])):
@@ -40,26 +40,44 @@ class Pointer(Generic[PT]):
40
40
  * **Setter**: it updates the value of the variable to its own (if variable was given instead of literal).
41
41
  * **Deleter**: it also deletes the original variable (if variable was given instead of literal).
42
42
  ---
43
- Attributes:
44
- value (`Any`, Hidden): Object to point to.
45
- attr (`str`|`None`, Hidden): Attribute of class instance. Only if `value` is a class instance.
46
- name (`str`, Hidden): Name of the global variable to which the pointer is pointing.
47
- Could require an input from the user to introduce the name of the variable if more than one is found.
48
- vars_dict (`dict[str,Any]`, Hidden): Dictionary of variables.
49
- `vars(modules["__main__"])` if pointing to a global variable and `inspect.currentframe().f_back.f_locals` if pointing to a local variable.\n
50
- ---
51
- ## Methods
52
- * `point_to`: Changes the variable or attribute the pointer is pointed to.
53
- * `switch_ref`: Allows to switch between the references pointing to the same value.
54
- * `print_refs`: Prints all the references pointing to the value.
55
- ---
56
- ## Properties\n
57
- :value: *`MethodType`*\n
58
- Points to `value` (or `value.attr`). Called through `<instance@Pointer>.value`. All three possible objects (getter, setter and deleter) have been declared.
59
- :reference: *`MethodType`*\n
60
- Pointed reference. Called through `<instance@Pointer>.reference`. **Only getter** defined.
61
- :attr: *`MethodType`*\n
62
- Name of the attribute of the pointed class instance. Called through `<instance@Pointer>.attr`. **Only getter** defined.\n
43
+
44
+ Attributes
45
+ ----------
46
+ value : `Any`, Hidden
47
+ Object to point to.
48
+ attr : `str`|`None`, Hidden
49
+ Attribute of class instance. Only if `value` is a class instance.
50
+ name : `str`, Hidden
51
+ Name of the global variable to which the pointer is pointing.
52
+ Could require an input from the user to introduce the name of the variable if more than one is found.
53
+ vars_dict : `dict[str,Any]`, Hidden
54
+ Dictionary of variables.
55
+ `vars(modules["__main__"])` if pointing to a global variable and
56
+ `inspect.currentframe().f_back.f_locals` if pointing to a local variable.
57
+
58
+ Methods
59
+ -------
60
+ **point_to**
61
+ Changes the variable or attribute the pointer is pointed to.
62
+ **switch_ref**
63
+ Allows to switch between the references pointing to the same value.
64
+ **print_refs**
65
+ Prints all the references pointing to the value.
66
+
67
+ Properties
68
+ ----------
69
+ **value**
70
+ Points to `value` (or `value.attr`).
71
+ Called through `<instance@Pointer>.value`.
72
+ All three possible objects (getter, setter and deleter) have been declared.
73
+ **reference**
74
+ Pointed reference.
75
+ Called through `<instance@Pointer>.reference`.
76
+ **Only getter** defined.
77
+ **attr**
78
+ Name of the attribute of the pointed class instance.
79
+ Called through `<instance@Pointer>.attr`.
80
+ **Only getter** defined.
63
81
  ---
64
82
  ## Currently supported
65
83
  Both global and local variables can be pointed at.
@@ -73,11 +91,16 @@ class Pointer(Generic[PT]):
73
91
  # Constructor (__init__)
74
92
  def __init__(self,value=None,reference:str|None=None,*,attr:str|None=None,local:bool=False):
75
93
  """
76
- Arguments:
77
- value (`Any`, Optional): Object to point to. If want to point to a class instance atribute, pass to this argument the class instance without the atribute.
78
- reference (`str`|`None`, Optional): Name linked to the value to point to. Useful in case there are multiple references pointing to the same value.
79
- attr (`str`|`None`, Optional): Atribute of the class instance to which you want to point. Leave empty if `value` is not a class instance.
80
- local (`bool`, Optional): Indicates if the value to point to is a local variable (`True` for yes and `False` for no). `False` by default.
94
+ Arguments
95
+ ---------
96
+ value : `Any`, Optional
97
+ Object to point to. If want to point to a class instance atribute, pass to this argument the class instance without the atribute.
98
+ reference : `str`|`None`, Optional
99
+ Name linked to the value to point to. Useful in case there are multiple references pointing to the same value.
100
+ attr : `str`|`None`, Optional
101
+ Attribute of the class instance to which you want to point. Leave empty if `value` is not a class instance.
102
+ local : `bool`, Optional
103
+ Indicates if the value to point to is a local variable (`True` for yes and `False` for no). `False` by default.
81
104
  """
82
105
  if local:
83
106
  vars_dict=currentframe().f_back.f_locals
@@ -105,12 +128,16 @@ class Pointer(Generic[PT]):
105
128
  # Point to
106
129
  def point_to(self,reference:str|None=None,value=None,*,attr:str|None=None):
107
130
  """
108
- Changes the address which the pointer points to.\n
109
- ---
110
- Arguments:
111
- reference (`str`|`None`, Optional): Reference pointing to the desired value. If wanted class attribute, introduce the reference for the class object.
112
- value (`Any`|`None`, Optional): Value to point to. If wanted class attribute, introduce just the class object.
113
- attr (`str`|`None`, Optional): Attribute of the class if class object was passed through `reference` or `value`.
131
+ Changes the address which the pointer points to.
132
+
133
+ Arguments
134
+ ---------
135
+ reference : `str`|`None`, Optional
136
+ Reference pointing to the desired value. If wanted class attribute, introduce the reference for the class object.
137
+ value : `Any`|`None`, Optional
138
+ Value to point to. If wanted class attribute, introduce just the class object.
139
+ attr : `str`|`None`, Optional
140
+ Attribute of the class if class object was passed through `reference` or `value`.
114
141
  """
115
142
  if not reference and not value:
116
143
  pass
@@ -150,10 +177,12 @@ class Pointer(Generic[PT]):
150
177
  # Switch reference
151
178
  def switch_ref(self,reference:str):
152
179
  """
153
- Allows to switch between references pointing to the same current value of the pointer.\n
154
- ---
155
- Arguments:
156
- reference (`str`): Reference to switch the pointer to.
180
+ Allows to switch between references pointing to the same current value of the pointer.
181
+
182
+ Arguments
183
+ ---------
184
+ reference : `str`
185
+ Reference to switch the pointer to.
157
186
  """
158
187
  if reference in self._vars_dict and self._vars_dict[reference] is not self.value:
159
188
  raise ValueError(f"Name \"{reference}\" doesn't point to pointer's value \"{self.value}\"")
@@ -168,6 +197,7 @@ class Pointer(Generic[PT]):
168
197
  """
169
198
  refs=[key for key,v in self._vars_dict.items() if v is self._value]
170
199
  refs=refs if len(refs)!=0 else [None]
200
+ print(refs)
171
201
 
172
202
  #* PROPERTIES
173
203
  # Value
@@ -30,9 +30,10 @@ def pointerize(func):
30
30
 
31
31
  The decorated function is still able to receive its normally expected parameters.
32
32
 
33
- ---
34
- Arguments:
35
- func (`FunctionType`): Decorated function.
33
+ Arguments
34
+ ---------
35
+ func : `FunctionType`
36
+ Decorated function.
36
37
  """
37
38
  # Makes the decorating function to keep its identity
38
39
  @wraps(func)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: Adds support for memory management
5
5
  Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = memorymanagement
3
- version = 1.2.0
3
+ version = 1.2.2
4
4
  author = Ricardo Werner Rivas
5
5
  author_email = ricardowernerrivas@gmail.com
6
6
  description = Adds support for memory management