memorymanagement 1.4.4__tar.gz → 1.4.6__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,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.4.4
4
- Summary: Adds support for memory management
3
+ Version: 1.4.6
4
+ Summary: Adds support for memory cleaning and pointers
5
5
  Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
7
7
  Author-email: ricardowernerrivas@gmail.com
@@ -15,8 +15,6 @@
15
15
  #* IMPORTS
16
16
  # Import "TypeVar" and "Generic"
17
17
  from typing import TypeVar,Generic
18
- # Import "modules" from "sys" package
19
- from sys import modules
20
18
  # Import "currentframe" from "inspect" package
21
19
  from inspect import currentframe
22
20
  # Define type with TypeVar
@@ -88,7 +86,7 @@ class Pointer(Generic[PT]):
88
86
  """
89
87
  #* METHODS
90
88
  # Constructor (__init__)
91
- def __init__(self,value=None,reference:str|None=None,*,attr:str|None=None,local:bool=False):
89
+ def __init__(self,value=None,reference:str|None=None,*,attr:str|None=None):
92
90
  """
93
91
  Arguments
94
92
  ---------
@@ -101,18 +99,9 @@ class Pointer(Generic[PT]):
101
99
  local : `bool`, Optional
102
100
  Indicates if the value to point to is a local variable (`True` for yes and `False` for no). `False` by default.
103
101
  """
104
- # If pointing to local variable
105
- if local:
106
- # Take the local frame
107
- vars_dict=currentframe().f_back.f_locals
108
- # Else
109
- else:
110
- # Take the global frame
111
- vars_dict=vars(modules["__main__"])
112
-
113
102
  # Store hidden attributes "_attr" and "_vars_dict"
114
103
  self._attr=attr # Instance attribute to point to
115
- self._vars_dict=vars_dict # Variables' frame
104
+ self._vars_dict=vars_dict=currentframe().f_back.f_locals # Variables' frame
116
105
 
117
106
  # If no value or reference is given
118
107
  if not value and not reference:
@@ -144,20 +133,22 @@ class Pointer(Generic[PT]):
144
133
  else:
145
134
  # Raise a "NameError"
146
135
  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)
136
+ # Else (only value)
158
137
  else:
159
- # Raise a "NameError"
160
- raise NameError(f"No reference is pointing to given value \"{value}\" ({value.__class__.__name__})")
138
+ # If the given value is between the variables' frame values
139
+ if value in vars_dict.values():
140
+ # Loop for the variables' frame
141
+ for key,v in vars_dict.items():
142
+ # If the current value is the given value
143
+ if v is value:
144
+ # The current key is the reference
145
+ name=key
146
+ # Break
147
+ break
148
+ # Else
149
+ else:
150
+ # Raise a "NameError"
151
+ raise NameError(f"No reference is pointing to given value \"{value}\" ({value.__class__.__name__})")
161
152
 
162
153
  # Set argument "value" as the pointer's value
163
154
  self._value=value
@@ -243,30 +234,32 @@ class Pointer(Generic[PT]):
243
234
  else:
244
235
  # Raise a "NameError"
245
236
  raise NameError(f"Name \"{reference}\" is not defined")
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
256
- # If an instance's attribute name is given
257
- if attr:
258
- # If the attribute belongs to the new value
259
- if attr in dir(self._value):
260
- # Store the attribute name into its corresponding hidden attribute
261
- self._attr=attr
262
- # Else
263
- else:
264
- # Raise an "AttributeError"
265
- raise AttributeError(f"\"{attr}\" is not an attribute of \"{self._value}\"")
266
- # Else (value not referenced)
237
+ # Else (only value)
267
238
  else:
268
- # Raise a "NameError"
269
- raise NameError(f"No reference is pointing to given value \"{self._value}\"")
239
+ # If the given value is between the variables' frame's values
240
+ if value in self._vars_dict:
241
+ # Loop for the variables' frame
242
+ for key,v in self._vars_dict.items():
243
+ # If the current value is the given value
244
+ if v is value:
245
+ # The current key is the reference and the given value is set as pointer's value
246
+ self._name,self._value=key,value
247
+ # Break
248
+ break
249
+ # If an instance's attribute name is given
250
+ if attr:
251
+ # If the attribute belongs to the new value
252
+ if attr in dir(self._value):
253
+ # Store the attribute name into its corresponding hidden attribute
254
+ self._attr=attr
255
+ # Else
256
+ else:
257
+ # Raise an "AttributeError"
258
+ raise AttributeError(f"\"{attr}\" is not an attribute of \"{self._value}\"")
259
+ # Else
260
+ else:
261
+ # Raise a "NameError"
262
+ raise NameError(f"No reference is pointing to given value \"{self._value}\"")
270
263
 
271
264
  # Get references
272
265
  def get_refs(self)->tuple[str]:
@@ -276,13 +269,13 @@ class Pointer(Generic[PT]):
276
269
  # Find and return all the references pointing to the pointer's value
277
270
  return tuple(key for key,v in self._vars_dict.items() if v is self._value)
278
271
 
279
- # Print references
280
- def print_refs(self):
281
- """
282
- Prints all the references pointing to the same current value of the pointer.
283
- """
284
- # Print all the references pointing to the pointer's value
285
- print(tuple(key for key,v in self._vars_dict.items() if v is self._value))
272
+ #// # Print references
273
+ #// def print_refs(self):
274
+ #// """
275
+ #// Prints all the references pointing to the same current value of the pointer.
276
+ #// """
277
+ #// # Print all the references pointing to the pointer's value
278
+ #// print(tuple(key for key,v in self._vars_dict.items() if v is self._value))
286
279
 
287
280
  # Switch reference
288
281
  def switch_ref(self,reference:str):
@@ -582,7 +575,7 @@ class Pointer(Generic[PT]):
582
575
  #* SCREEN
583
576
  # Representation
584
577
  def __repr__(self):
585
- return f"{self.__class__.__name__}({self.value})"
578
+ return f"{self.__class__.__name__}({self.value},{self.reference},attr={self.attr})"
586
579
 
587
580
  # HTML representation
588
581
  def _repr_html_(self):
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: memorymanagement
3
- Version: 1.4.4
4
- Summary: Adds support for memory management
3
+ Version: 1.4.6
4
+ Summary: Adds support for memory cleaning and pointers
5
5
  Home-page: https://github.com/Ricardo-Werner-Rivas/memorymanagement/tree/PyPI
6
6
  Author: Ricardo Werner Rivas
7
7
  Author-email: ricardowernerrivas@gmail.com
@@ -1,9 +1,9 @@
1
1
  [metadata]
2
2
  name = memorymanagement
3
- version = 1.4.4
3
+ version = 1.4.6
4
4
  author = Ricardo Werner Rivas
5
5
  author_email = ricardowernerrivas@gmail.com
6
- description = Adds support for memory management
6
+ description = Adds support for memory cleaning and pointers
7
7
  long_description = file:README.md
8
8
  long_description_content_type = text/markdown
9
9
  license = MIT