1066 | | return self._coercion_maps.get(R, S, None) |
| 1068 | refs = self._coercion_maps.get(R, S, None) |
| 1069 | if refs is None: |
| 1070 | return None |
| 1071 | R_map_ref, S_map_ref = refs |
| 1072 | if R_map_ref is None: |
| 1073 | S_map = <object>PyWeakref_GET_OBJECT(S_map_ref) |
| 1074 | if S_map is not None: |
| 1075 | return None, S_map |
| 1076 | elif S_map_ref is None: |
| 1077 | R_map = <object>PyWeakref_GET_OBJECT(R_map_ref) |
| 1078 | if R_map is not None: |
| 1079 | return R_map, None |
| 1080 | else: |
| 1081 | R_map = <object>PyWeakref_GET_OBJECT(R_map_ref) |
| 1082 | S_map = <object>PyWeakref_GET_OBJECT(S_map_ref) |
| 1083 | if R_map is not None and S_map is not None: |
| 1084 | return R_map, S_map |
1068 | | homs = self.discover_coercion(R, S) |
1069 | | if 0: |
1070 | | # This breaks too many things that are going to change |
1071 | | # in the new coercion model anyways. |
1072 | | # COERCE TODO: Enable it then. |
1073 | | homs = self.verify_coercion_maps(R, S, homs) |
| 1086 | pass |
| 1087 | homs = self.discover_coercion(R, S) |
| 1088 | if 0: |
| 1089 | # This breaks too many things that are going to change |
| 1090 | # in the new coercion model anyways. |
| 1091 | # COERCE TODO: Enable it then. |
| 1092 | homs = self.verify_coercion_maps(R, S, homs) |
| 1093 | else: |
| 1094 | if homs is not None: |
| 1095 | x_map, y_map = homs |
| 1096 | if x_map is not None and not isinstance(x_map, Map): |
| 1097 | raise RuntimeError, "BUG in coercion model: coerce_map_from must return a Map" |
| 1098 | if y_map is not None and not isinstance(y_map, Map): |
| 1099 | raise RuntimeError, "BUG in coercion model: coerce_map_from must return a Map" |
| 1100 | if homs is None: |
| 1101 | refs = None |
| 1102 | swap = None |
| 1103 | else: |
| 1104 | R_map, S_map = homs |
| 1105 | R_map_ref = None if R_map is None else PyWeakref_NewRef(R_map, None) |
| 1106 | S_map_ref = None if S_map is None else PyWeakref_NewRef(S_map, None) |
| 1107 | refs = R_map_ref, S_map_ref |
| 1108 | if R_map is None and PY_TYPE_CHECK(S, Parent) and (<Parent>S).has_coerce_map_from(R): |
| 1109 | swap = None, PyWeakref_NewRef((<Parent>S).coerce_map_from(R), None) |
1075 | | if homs is not None: |
1076 | | x_map, y_map = homs |
1077 | | if x_map is not None and not isinstance(x_map, Map): |
1078 | | raise RuntimeError, "BUG in coercion model: coerce_map_from must return a Map" |
1079 | | if y_map is not None and not isinstance(y_map, Map): |
1080 | | raise RuntimeError, "BUG in coercion model: coerce_map_from must return a Map" |
1081 | | if homs is None: |
1082 | | swap = None |
1083 | | else: |
1084 | | R_map, S_map = homs |
1085 | | if R_map is None and PY_TYPE_CHECK(S, Parent) and (<Parent>S).has_coerce_map_from(R): |
1086 | | swap = None, (<Parent>S).coerce_map_from(R) |
1087 | | else: |
1088 | | swap = S_map, R_map |
1089 | | self._coercion_maps.set(R, S, None, homs) |
1090 | | self._coercion_maps.set(S, R, None, swap) |
| 1111 | swap = S_map_ref, R_map_ref |
| 1112 | self._coercion_maps.set(R, S, None, refs) |
| 1113 | self._coercion_maps.set(S, R, None, swap) |