Skip to content

Commit 61699e5

Browse files
committed
Remove redundant code
Three classes that inherit from NodeInfoBase - FileNodeInfo, AliasNodeInfo and ValueNodeInfo - have "specializations" of __getstate_ and __setstate__ from the parent, but they're identical to the parent's and thus not needed. Always easy to add back if a different implementation is ever needed for any of them. Signed-off-by: Mats Wichmann <[email protected]>
1 parent 7e64842 commit 61699e5

File tree

4 files changed

+3
-94
lines changed

4 files changed

+3
-94
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
1919
json output is also sorted, to match the default display.
2020
- Python 3.13 (alpha) changes the behavior of isabs() on Windows. Adjust
2121
SCons usage of in NodeInfo classes to match. Fixes #4502, #4504.
22+
- Drop duplicated __getstate__ and __setstate__ methods in AliasNodeInfo,
23+
FileNodeInfo and ValueNodeInfo classes, as they are identical to the
24+
ones in parent NodeInfoBase and can just be inherited.
2225

2326

2427
RELEASE 4.7.0 - Sun, 17 Mar 2024 17:22:20 -0700

SCons/Node/Alias.py

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,38 +57,6 @@ class AliasNodeInfo(SCons.Node.NodeInfoBase):
5757
def str_to_node(self, s):
5858
return default_ans.Alias(s)
5959

60-
def __getstate__(self):
61-
"""
62-
Return all fields that shall be pickled. Walk the slots in the class
63-
hierarchy and add those to the state dictionary. If a '__dict__' slot is
64-
available, copy all entries to the dictionary. Also include the version
65-
id, which is fixed for all instances of a class.
66-
"""
67-
state = getattr(self, '__dict__', {}).copy()
68-
for obj in type(self).mro():
69-
for name in getattr(obj,'__slots__',()):
70-
if hasattr(self, name):
71-
state[name] = getattr(self, name)
72-
73-
state['_version_id'] = self.current_version_id
74-
try:
75-
del state['__weakref__']
76-
except KeyError:
77-
pass
78-
79-
return state
80-
81-
def __setstate__(self, state) -> None:
82-
"""
83-
Restore the attributes from a pickled state.
84-
"""
85-
# TODO check or discard version
86-
del state['_version_id']
87-
for key, value in state.items():
88-
if key not in ('__weakref__',):
89-
setattr(self, key, value)
90-
91-
9260
class AliasBuildInfo(SCons.Node.BuildInfoBase):
9361
__slots__ = ()
9462
current_version_id = 2

SCons/Node/FS.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2528,37 +2528,6 @@ def str_to_node(self, s):
25282528
s = top.get_labspath() + '/' + s
25292529
return root._lookup_abs(s, Entry)
25302530

2531-
def __getstate__(self):
2532-
"""
2533-
Return all fields that shall be pickled. Walk the slots in the class
2534-
hierarchy and add those to the state dictionary. If a '__dict__' slot is
2535-
available, copy all entries to the dictionary. Also include the version
2536-
id, which is fixed for all instances of a class.
2537-
"""
2538-
state = getattr(self, '__dict__', {}).copy()
2539-
for obj in type(self).mro():
2540-
for name in getattr(obj, '__slots__', ()):
2541-
if hasattr(self, name):
2542-
state[name] = getattr(self, name)
2543-
2544-
state['_version_id'] = self.current_version_id
2545-
try:
2546-
del state['__weakref__']
2547-
except KeyError:
2548-
pass
2549-
2550-
return state
2551-
2552-
def __setstate__(self, state) -> None:
2553-
"""
2554-
Restore the attributes from a pickled state.
2555-
"""
2556-
# TODO check or discard version
2557-
del state['_version_id']
2558-
for key, value in state.items():
2559-
if key not in ('__weakref__',):
2560-
setattr(self, key, value)
2561-
25622531
def __eq__(self, other):
25632532
return self.csig == other.csig and self.timestamp == other.timestamp and self.size == other.size
25642533

SCons/Node/Python.py

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -37,37 +37,6 @@ class ValueNodeInfo(SCons.Node.NodeInfoBase):
3737
def str_to_node(self, s):
3838
return ValueWithMemo(s)
3939

40-
def __getstate__(self):
41-
"""
42-
Return all fields that shall be pickled. Walk the slots in the class
43-
hierarchy and add those to the state dictionary. If a '__dict__' slot
44-
is available, copy all entries to the dictionary. Also include the
45-
version id, which is fixed for all instances of a class.
46-
"""
47-
state = getattr(self, '__dict__', {}).copy()
48-
for obj in type(self).mro():
49-
for name in getattr(obj, '__slots__', ()):
50-
if hasattr(self, name):
51-
state[name] = getattr(self, name)
52-
53-
state['_version_id'] = self.current_version_id
54-
try:
55-
del state['__weakref__']
56-
except KeyError:
57-
pass
58-
59-
return state
60-
61-
def __setstate__(self, state) -> None:
62-
"""
63-
Restore the attributes from a pickled state.
64-
"""
65-
# TODO check or discard version
66-
del state['_version_id']
67-
for key, value in state.items():
68-
if key not in ('__weakref__',):
69-
setattr(self, key, value)
70-
7140

7241
class ValueBuildInfo(SCons.Node.BuildInfoBase):
7342
__slots__ = ()

0 commit comments

Comments
 (0)