Repository navigation
Remove typedict - #338
Remove typedict#338
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-3.0 #338 +/- ##
===============================================
- Coverage 93.99% 93.78% -0.22%
===============================================
Files 48 48
Lines 3946 3764 -182
===============================================
- Hits 3709 3530 -179
+ Misses 237 234 -3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
|
I have second thoughts about this. Maybe add/modify with some more obvious syntax, like def __getitem__(self, name: str) -> object:
return self._store[name]
def __contains__(self, name: object) -> bool:
return name in self._store
def __iter__(self):
return iter(list(self._store))
def __len__(self) -> int:
return len(self._store)
def names(self) -> list[str]: ... # was vertices()
def objects(self) -> list[object]: ... # unchanged
def add(self, obj) -> None: ... # was add_vertex()
def discard(self, name: str) -> None: ... # was prune()
def clear(self) -> None: ... # was _clear()THis adds support for |
|
Yes, I support renaming the methods to a more dict-like or list-like representation. I would also rename the object itself, maybe to |
I would propose |
damskii9992
left a comment
There was a problem hiding this comment.
Small comments. Pending renaming of class and methods for full approval.
| def __init__(self): | ||
| # A dictionary of object names and their corresponding objects | ||
| self._store = weakref.WeakValueDictionary() | ||
| # A dict with object names as keys and a list of their object types as values, with weak references |
There was a problem hiding this comment.
I would probably keep the comment. It's useful for newcomers who don't know what a WeakValueDictionary is.
There was a problem hiding this comment.
I kept the second comment only as they overlapped.
Addressed. |
|
You merged this PR before approval . . . |
You said:
both renamings were done. I assumed approval on this condition. freeing up |
Maphas gone from a typed object graph to a plain weak-reference registry indexed byunique_name.Current structure of
Map:_store. This removes the stale entry cleanup inadd_vertexand in the finalizer callbacks.WeakValueDictionarydeletes the stale entries, so iterating thelistover it is safe during changes.get_item_by_keydoes a single lookup withtry/except KeyErrorinstead of checking and then indexing.pruneused to delete only when the name was in__type_dict. It now always does_store.pop(key).objects()returns objects as a list of strong references, so they stay alive until the list is released.unique_namesetter callsadd_vertexagain without pruning the old name. A renamed object is registered with both names and can appear twice inobjects(). Its old name still shows invertices(). Explained in docstrings.