memorymanagement 1.4.2__tar.gz → 1.4.4__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.4.2
3
+ Version: 1.4.4
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
@@ -83,7 +83,7 @@ class Pointer(Generic[PT]):
83
83
 
84
84
  Literals are **not** supported because of it being useless. Literals do **not** work anymore.
85
85
  The only use for introducing a literal instead of a referenced value is for the class code to bind the instance
86
- to an unknown reference pointing to the given value or to display all the references pointing to the given literal
86
+ to an unknown reference pointing to the given value or to display all the references pointing to the given literal, through the `get_refs` or `print_refs` methods,
87
87
  if there is more than one.
88
88
  """
89
89
  #* METHODS
@@ -110,17 +110,16 @@ class Pointer(Generic[PT]):
110
110
  # Take the global frame
111
111
  vars_dict=vars(modules["__main__"])
112
112
 
113
- # Store hidden attributes
114
- self._value=value # Pointer's value
115
- self._vars_dict=vars_dict # Variables' frame
113
+ # Store hidden attributes "_attr" and "_vars_dict"
116
114
  self._attr=attr # Instance attribute to point to
115
+ self._vars_dict=vars_dict # Variables' frame
117
116
 
118
- # If there is an instance's attribute to point to and it doesn't belong to the given value
119
- if self._attr and self._attr not in dir(self._value):
120
- # Raise an "AttributeError"
121
- raise AttributeError(f"\"{attr}\" is not an attribute of \"{self._value}\"")
122
- # If a reference is given
123
- if reference:
117
+ # If no value or reference is given
118
+ if not value and not reference:
119
+ # Raise a "ValueError"
120
+ raise ValueError("Either a value or a reference is needed")
121
+ # Else, if a reference is given
122
+ elif value and reference:
124
123
  # If the reference is in the variables' frame and points to the given value
125
124
  if reference in vars_dict and vars_dict[reference] is value:
126
125
  # Store the reference in "name" local variable
@@ -133,18 +132,42 @@ class Pointer(Generic[PT]):
133
132
  elif vars_dict[reference] is not value:
134
133
  # Raise a "ValueError"
135
134
  raise ValueError(f"Name \"{reference}\" doesn't point to given value ({value})")
136
- # Else
135
+ # Else, if only a reference is given
136
+ elif reference:
137
+ # If the given reference is in the variables' frame
138
+ if reference in vars_dict:
139
+ # Store the reference into local variable "name"
140
+ name=reference
141
+ # Store the value the reference is pointing to in argument "value"
142
+ value=vars_dict[reference]
143
+ # Else
144
+ else:
145
+ # Raise a "NameError"
146
+ raise NameError(f"Name \"{reference}\" is not defined")
147
+ # Else, if only a value is given an it is between the variables' frame's values
148
+ elif value and value in vars_dict.values():
149
+ # Loop for the variables' frame
150
+ for key,v in vars_dict.items():
151
+ # If the current value is the given value
152
+ if v is value:
153
+ # The current key is the reference
154
+ name=key
155
+ # Break
156
+ break
157
+ # Else (value not referenced)
137
158
  else:
138
- # Store every reference pointing to the given value
139
- name=[key for key,v in vars_dict.items() if v is value]
140
- # Set to "None" if no reference was found
141
- name=name[0] if len(name)!=0 else None
159
+ # Raise a "NameError"
160
+ raise NameError(f"No reference is pointing to given value \"{value}\" ({value.__class__.__name__})")
161
+
162
+ # Set argument "value" as the pointer's value
163
+ self._value=value
142
164
  # Store the reference in the hidden attribute "_name"
143
165
  self._name=name
144
- # If there is no reference
145
- if self._name==None:
146
- # Raise a "NameError"
147
- raise NameError(f"No reference is pointing to given value \"{self._value}\"")
166
+
167
+ # If there is an instance's attribute to point to and it doesn't belong to the given value
168
+ if attr and attr not in dir(value):
169
+ # Raise an "AttributeError"
170
+ raise AttributeError(f"\"{attr}\" is not an attribute of \"{value}\"")
148
171
 
149
172
  # Point to
150
173
  def point_to(self,value=None,reference:str|None=None,*,attr:str|None=None):
@@ -153,15 +176,15 @@ class Pointer(Generic[PT]):
153
176
 
154
177
  Arguments
155
178
  ---------
156
- reference : `str`|`None`, Optional
157
- Reference pointing to the desired value. If wanted class attribute, introduce the reference for the class instance.
158
179
  value : `Any`|`None`, Optional
159
180
  Value to point to. If wanted class attribute, introduce just the class object.
181
+ reference : `str`|`None`, Optional
182
+ Reference pointing to the desired value. If wanted class attribute, introduce the reference for the class instance.
160
183
  attr : `str`|`None`, Optional
161
184
  Attribute of the class if class object was passed through `reference` or `value`.
162
185
  """
163
186
  # If no reference or value is given
164
- if not reference and not value:
187
+ if not value and not reference:
165
188
  # If an instance's attribute name is given
166
189
  if attr:
167
190
  # If the attribute belongs to the pointer's value
@@ -220,16 +243,16 @@ class Pointer(Generic[PT]):
220
243
  else:
221
244
  # Raise a "NameError"
222
245
  raise NameError(f"Name \"{reference}\" is not defined")
223
- # Else, if only a value is given
224
- elif value:
225
- # Store the given value and its references into their corresponding hidden attributes
226
- self._name,self._value=[key for key,v in self._vars_dict.items() if v is value],value
227
- # Modify the "_name" hidden attribute to be a string or "None"
228
- self._name=self._name[0] if len(self._name)!=0 else None
229
- # If no reference was found
230
- if self._name==None:
231
- # Raise a "NameError"
232
- raise NameError(f"No reference is pointing to given value \"{self._value}\"")
246
+ # Else, if only a value is given an it is between the variables' frame's values
247
+ elif value and value in self._vars_dict:
248
+ # Loop for the variables' frame
249
+ for key,v in self._vars_dict.items():
250
+ # If the current value is the given value
251
+ if v is value:
252
+ # The current key is the reference and the given value is set as pointer's value
253
+ self._name,self._value=key,value
254
+ # Break
255
+ break
233
256
  # If an instance's attribute name is given
234
257
  if attr:
235
258
  # If the attribute belongs to the new value
@@ -240,6 +263,10 @@ class Pointer(Generic[PT]):
240
263
  else:
241
264
  # Raise an "AttributeError"
242
265
  raise AttributeError(f"\"{attr}\" is not an attribute of \"{self._value}\"")
266
+ # Else (value not referenced)
267
+ else:
268
+ # Raise a "NameError"
269
+ raise NameError(f"No reference is pointing to given value \"{self._value}\"")
243
270
 
244
271
  # Get references
245
272
  def get_refs(self)->tuple[str]:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.4.2
3
+ Version: 1.4.4
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.4.2
3
+ version = 1.4.4
4
4
  author = Ricardo Werner Rivas
5
5
  author_email = ricardowernerrivas@gmail.com
6
6
  description = Adds support for memory management