summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Smith <bruce@nanorex.com>2009-02-06 17:40:13 +0000
committerBruce Smith <bruce@nanorex.com>2009-02-06 17:40:13 +0000
commitf95c6dd26add0c93876d0d2081bf0cd44ef3ff70 (patch)
tree7c5d85bfbbc099d114e2c3a73a909448e600495f
parentc05cc24bf97cbb53e2d43872a41c205cc6913e8d (diff)
downloadnanoengineer-f95c6dd26add0c93876d0d2081bf0cd44ef3ff70.tar.gz
nanoengineer-f95c6dd26add0c93876d0d2081bf0cd44ef3ff70.zip
comment on same_vals/__eq__/new-style/Bond interaction
-rwxr-xr-xcad/src/model/bonds.py28
-rw-r--r--cad/src/utilities/Comparison.py5
2 files changed, 31 insertions, 2 deletions
diff --git a/cad/src/model/bonds.py b/cad/src/model/bonds.py
index eef1633fc..a9e8df977 100755
--- a/cad/src/model/bonds.py
+++ b/cad/src/model/bonds.py
@@ -98,6 +98,14 @@ if usePyrexAtomsAndBonds(): #bruce 080220 revised this
# usePyrexAtomsAndBonds tests that we want to, and can, import all
# necessary symbols from atombase
from atombase import BondDictBase, BondBase
+
+ # WARNING: same_vals probably uses __eq__ for Bond when it inherits from
+ # BondBase (a new-style class), and this could conceivably cause Undo bugs;
+ # a warning is printed lower down if Bond is new-style for any reason
+ # (search for is_new_style_class(Bond) to find it).
+ # For more info see 090205 comments in state_utils.py docstring
+ # and in Comparison.py. [bruce 090205]
+
class BondDict(BondDictBase):
# not yet used, except maybe in atombasetests.py
# renamed from BondSet, bruce 080229
@@ -2292,6 +2300,26 @@ class Bond(BondBase, StateMixin, Selobj_API): #bruce 041109 partial rewrite
register_instancelike_class( Bond) # ericm & bruce 080225
+def is_new_style_class(c): #bruce 090206, refile
+ # I'm not sure if this is the best test, but it's the best I have now.
+ # isinstance(c, object) is true for both old and new style classes;
+ # the type of c varies (classobj or type) but I'm not sure if the specific
+ # types are guaranteed, and I don't want to exclude metaclasses (subclasses
+ # of type), and for all I know classobj might be (or become someday)
+ # a subclass of type.
+ return hasattr(c, '__mro__')
+
+if is_new_style_class(Bond): #bruce 090205
+ # see comments in state_utils.py docstring, Comparison.py, and above;
+ # register_instancelike_class doesn't yet handle same_vals.
+ # The comments also say how to fix this (not hard, but does require
+ # changes to the C version of same_vals).
+ msg = "WARNING: Bond (%r) is new-style -- possible Undo bugs related " \
+ "to same_vals; see comments dated 090205" % Bond
+ print msg
+ assert 0, msg + ". Assert 0 to make sure this is noticed."
+ # ok to remove this assertion for testing atombase
+
register_class_changedicts( Bond, _Bond_global_dicts )
# error if one class has two same-named changedicts
# (so be careful re module reload)
diff --git a/cad/src/utilities/Comparison.py b/cad/src/utilities/Comparison.py
index de33eb983..b15d7df8c 100644
--- a/cad/src/utilities/Comparison.py
+++ b/cad/src/utilities/Comparison.py
@@ -282,7 +282,7 @@ def _same_dict_helper(v1, v2):
#
# Conclusion: we can ignore extending _same_InstanceType_helper to new-style
# Nodes -- in fact, we could dispense with it entirely in current code except
-# for Bond.
+# for Bond. (See also the 090205 comments in the docstring of state_utils.py.)
#
# (FYI: If we were to write a completely new framework, I think we'd use our
# own classes rather than Numeric, with proper semantics for ==/!=,
@@ -412,7 +412,8 @@ def _same_vals_helper(v1, v2): #060303
raise _NotTheSame
same_helper = _known_type_same_helpers.get(typ) # a fixed public dictionary
# note: this has an entry for InstanceType (necessary only for Bond)
- # but not for new-style classes. This is ok; see comments dated 090205.
+ # but not for new-style classes. This is ok (as long as Bond remains an
+ # old-style class); see comments dated 090205.
if same_helper is not None:
# we optim by not storing any scanner for atomic types, or a few others
same_helper(v1, v2) # might raise _NotTheSame