|
33 | 33 | from warnings import warn |
34 | 34 | from xml.etree.ElementTree import Element as XmlElement # nosec B405 |
35 | 35 |
|
36 | | -import serializable |
| 36 | +import py_serializable as serializable |
37 | 37 | from sortedcontainers import SortedSet |
38 | 38 |
|
39 | 39 | from .._internal.compare import ComparableTuple as _ComparableTuple |
@@ -128,22 +128,23 @@ def classification(self) -> str: |
128 | 128 | def classification(self, classification: str) -> None: |
129 | 129 | self._classification = classification |
130 | 130 |
|
| 131 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 132 | + return _ComparableTuple(( |
| 133 | + self.flow, self.classification |
| 134 | + )) |
| 135 | + |
131 | 136 | def __eq__(self, other: object) -> bool: |
132 | 137 | if isinstance(other, DataClassification): |
133 | | - return hash(other) == hash(self) |
| 138 | + return self.__comparable_tuple() == other.__comparable_tuple() |
134 | 139 | return False |
135 | 140 |
|
136 | 141 | def __lt__(self, other: object) -> bool: |
137 | 142 | if isinstance(other, DataClassification): |
138 | | - return _ComparableTuple(( |
139 | | - self.flow, self.classification |
140 | | - )) < _ComparableTuple(( |
141 | | - other.flow, other.classification |
142 | | - )) |
| 143 | + return self.__comparable_tuple() < other.__comparable_tuple() |
143 | 144 | return NotImplemented |
144 | 145 |
|
145 | 146 | def __hash__(self) -> int: |
146 | | - return hash((self.flow, self.classification)) |
| 147 | + return hash(self.__comparable_tuple()) |
147 | 148 |
|
148 | 149 | def __repr__(self) -> str: |
149 | 150 | return f'<DataClassification flow={self.flow}>' |
@@ -231,22 +232,23 @@ def content(self) -> str: |
231 | 232 | def content(self, content: str) -> None: |
232 | 233 | self._content = content |
233 | 234 |
|
| 235 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 236 | + return _ComparableTuple(( |
| 237 | + self.content_type, self.encoding, self.content, |
| 238 | + )) |
| 239 | + |
234 | 240 | def __eq__(self, other: object) -> bool: |
235 | 241 | if isinstance(other, AttachedText): |
236 | | - return hash(other) == hash(self) |
| 242 | + return self.__comparable_tuple() == other.__comparable_tuple() |
237 | 243 | return False |
238 | 244 |
|
239 | 245 | def __lt__(self, other: Any) -> bool: |
240 | 246 | if isinstance(other, AttachedText): |
241 | | - return _ComparableTuple(( |
242 | | - self.content_type, self.content, self.encoding |
243 | | - )) < _ComparableTuple(( |
244 | | - other.content_type, other.content, other.encoding |
245 | | - )) |
| 247 | + return self.__comparable_tuple() < other.__comparable_tuple() |
246 | 248 | return NotImplemented |
247 | 249 |
|
248 | 250 | def __hash__(self) -> int: |
249 | | - return hash((self.content, self.content_type, self.encoding)) |
| 251 | + return hash(self.__comparable_tuple()) |
250 | 252 |
|
251 | 253 | def __repr__(self) -> str: |
252 | 254 | return f'<AttachedText content-type={self.content_type}, encoding={self.encoding}>' |
@@ -510,22 +512,23 @@ def content(self) -> str: |
510 | 512 | def content(self, content: str) -> None: |
511 | 513 | self._content = content |
512 | 514 |
|
| 515 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 516 | + return _ComparableTuple(( |
| 517 | + self.alg, self.content |
| 518 | + )) |
| 519 | + |
513 | 520 | def __eq__(self, other: object) -> bool: |
514 | 521 | if isinstance(other, HashType): |
515 | | - return hash(other) == hash(self) |
| 522 | + return self.__comparable_tuple() == other.__comparable_tuple() |
516 | 523 | return False |
517 | 524 |
|
518 | 525 | def __lt__(self, other: Any) -> bool: |
519 | 526 | if isinstance(other, HashType): |
520 | | - return _ComparableTuple(( |
521 | | - self.alg, self.content |
522 | | - )) < _ComparableTuple(( |
523 | | - other.alg, other.content |
524 | | - )) |
| 527 | + return self.__comparable_tuple() < other.__comparable_tuple() |
525 | 528 | return NotImplemented |
526 | 529 |
|
527 | 530 | def __hash__(self) -> int: |
528 | | - return hash((self.alg, self.content)) |
| 531 | + return hash(self.__comparable_tuple()) |
529 | 532 |
|
530 | 533 | def __repr__(self) -> str: |
531 | 534 | return f'<HashType {self.alg.name}:{self.content}>' |
@@ -728,7 +731,7 @@ def __init__(self, uri: str) -> None: |
728 | 731 |
|
729 | 732 | def __eq__(self, other: Any) -> bool: |
730 | 733 | if isinstance(other, XsUri): |
731 | | - return hash(other) == hash(self) |
| 734 | + return self._uri == other._uri |
732 | 735 | return False |
733 | 736 |
|
734 | 737 | def __lt__(self, other: Any) -> bool: |
@@ -887,25 +890,24 @@ def hashes(self) -> 'SortedSet[HashType]': |
887 | 890 | def hashes(self, hashes: Iterable[HashType]) -> None: |
888 | 891 | self._hashes = SortedSet(hashes) |
889 | 892 |
|
| 893 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 894 | + return _ComparableTuple(( |
| 895 | + self._type, self._url, self._comment, |
| 896 | + _ComparableTuple(self._hashes) |
| 897 | + )) |
| 898 | + |
890 | 899 | def __eq__(self, other: object) -> bool: |
891 | 900 | if isinstance(other, ExternalReference): |
892 | | - return hash(other) == hash(self) |
| 901 | + return self.__comparable_tuple() == other.__comparable_tuple() |
893 | 902 | return False |
894 | 903 |
|
895 | 904 | def __lt__(self, other: Any) -> bool: |
896 | 905 | if isinstance(other, ExternalReference): |
897 | | - return _ComparableTuple(( |
898 | | - self._type, self._url, self._comment |
899 | | - )) < _ComparableTuple(( |
900 | | - other._type, other._url, other._comment |
901 | | - )) |
| 906 | + return self.__comparable_tuple() < other.__comparable_tuple() |
902 | 907 | return NotImplemented |
903 | 908 |
|
904 | 909 | def __hash__(self) -> int: |
905 | | - return hash(( |
906 | | - self._type, self._url, self._comment, |
907 | | - tuple(sorted(self._hashes, key=hash)) |
908 | | - )) |
| 910 | + return hash(self.__comparable_tuple()) |
909 | 911 |
|
910 | 912 | def __repr__(self) -> str: |
911 | 913 | return f'<ExternalReference {self.type.name}, {self.url}>' |
@@ -964,22 +966,23 @@ def value(self) -> Optional[str]: |
964 | 966 | def value(self, value: Optional[str]) -> None: |
965 | 967 | self._value = value |
966 | 968 |
|
| 969 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 970 | + return _ComparableTuple(( |
| 971 | + self.name, self.value |
| 972 | + )) |
| 973 | + |
967 | 974 | def __eq__(self, other: object) -> bool: |
968 | 975 | if isinstance(other, Property): |
969 | | - return hash(other) == hash(self) |
| 976 | + return self.__comparable_tuple() == other.__comparable_tuple() |
970 | 977 | return False |
971 | 978 |
|
972 | 979 | def __lt__(self, other: Any) -> bool: |
973 | 980 | if isinstance(other, Property): |
974 | | - return _ComparableTuple(( |
975 | | - self.name, self.value |
976 | | - )) < _ComparableTuple(( |
977 | | - other.name, other.value |
978 | | - )) |
| 981 | + return self.__comparable_tuple() < other.__comparable_tuple() |
979 | 982 | return NotImplemented |
980 | 983 |
|
981 | 984 | def __hash__(self) -> int: |
982 | | - return hash((self.name, self.value)) |
| 985 | + return hash(self.__comparable_tuple()) |
983 | 986 |
|
984 | 987 | def __repr__(self) -> str: |
985 | 988 | return f'<Property name={self.name}>' |
@@ -1055,22 +1058,23 @@ def encoding(self) -> Optional[Encoding]: |
1055 | 1058 | def encoding(self, encoding: Optional[Encoding]) -> None: |
1056 | 1059 | self._encoding = encoding |
1057 | 1060 |
|
| 1061 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 1062 | + return _ComparableTuple(( |
| 1063 | + self.content, self.content_type, self.encoding |
| 1064 | + )) |
| 1065 | + |
1058 | 1066 | def __eq__(self, other: object) -> bool: |
1059 | 1067 | if isinstance(other, NoteText): |
1060 | | - return hash(other) == hash(self) |
| 1068 | + return self.__comparable_tuple() == other.__comparable_tuple() |
1061 | 1069 | return False |
1062 | 1070 |
|
1063 | 1071 | def __lt__(self, other: Any) -> bool: |
1064 | 1072 | if isinstance(other, NoteText): |
1065 | | - return _ComparableTuple(( |
1066 | | - self.content, self.content_type, self.encoding |
1067 | | - )) < _ComparableTuple(( |
1068 | | - other.content, other.content_type, other.encoding |
1069 | | - )) |
| 1073 | + return self.__comparable_tuple() < other.__comparable_tuple() |
1070 | 1074 | return NotImplemented |
1071 | 1075 |
|
1072 | 1076 | def __hash__(self) -> int: |
1073 | | - return hash((self.content, self.content_type, self.encoding)) |
| 1077 | + return hash(self.__comparable_tuple()) |
1074 | 1078 |
|
1075 | 1079 | def __repr__(self) -> str: |
1076 | 1080 | return f'<NoteText content_type={self.content_type}, encoding={self.encoding}>' |
@@ -1139,22 +1143,23 @@ def locale(self, locale: Optional[str]) -> None: |
1139 | 1143 | " ISO-3166 (or higher) country code. according to ISO-639 format. Examples include: 'en', 'en-US'." |
1140 | 1144 | ) |
1141 | 1145 |
|
| 1146 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 1147 | + return _ComparableTuple(( |
| 1148 | + self.locale, self.text |
| 1149 | + )) |
| 1150 | + |
1142 | 1151 | def __eq__(self, other: object) -> bool: |
1143 | 1152 | if isinstance(other, Note): |
1144 | | - return hash(other) == hash(self) |
| 1153 | + return self.__comparable_tuple() == other.__comparable_tuple() |
1145 | 1154 | return False |
1146 | 1155 |
|
1147 | 1156 | def __lt__(self, other: Any) -> bool: |
1148 | 1157 | if isinstance(other, Note): |
1149 | | - return _ComparableTuple(( |
1150 | | - self.locale, self.text |
1151 | | - )) < _ComparableTuple(( |
1152 | | - other.locale, other.text |
1153 | | - )) |
| 1158 | + return self.__comparable_tuple() < other.__comparable_tuple() |
1154 | 1159 | return NotImplemented |
1155 | 1160 |
|
1156 | 1161 | def __hash__(self) -> int: |
1157 | | - return hash((self.text, self.locale)) |
| 1162 | + return hash(self.__comparable_tuple()) |
1158 | 1163 |
|
1159 | 1164 | def __repr__(self) -> str: |
1160 | 1165 | return f'<Note id={id(self)}, locale={self.locale}>' |
@@ -1224,22 +1229,23 @@ def email(self) -> Optional[str]: |
1224 | 1229 | def email(self, email: Optional[str]) -> None: |
1225 | 1230 | self._email = email |
1226 | 1231 |
|
| 1232 | + def __comparable_tuple(self) -> _ComparableTuple: |
| 1233 | + return _ComparableTuple(( |
| 1234 | + self.timestamp, self.name, self.email |
| 1235 | + )) |
| 1236 | + |
1227 | 1237 | def __eq__(self, other: object) -> bool: |
1228 | 1238 | if isinstance(other, IdentifiableAction): |
1229 | | - return hash(other) == hash(self) |
| 1239 | + return self.__comparable_tuple() == other.__comparable_tuple() |
1230 | 1240 | return False |
1231 | 1241 |
|
1232 | 1242 | def __lt__(self, other: Any) -> bool: |
1233 | 1243 | if isinstance(other, IdentifiableAction): |
1234 | | - return _ComparableTuple(( |
1235 | | - self.timestamp, self.name, self.email |
1236 | | - )) < _ComparableTuple(( |
1237 | | - other.timestamp, other.name, other.email |
1238 | | - )) |
| 1244 | + return self.__comparable_tuple() < other.__comparable_tuple() |
1239 | 1245 | return NotImplemented |
1240 | 1246 |
|
1241 | 1247 | def __hash__(self) -> int: |
1242 | | - return hash((self.timestamp, self.name, self.email)) |
| 1248 | + return hash(self.__comparable_tuple()) |
1243 | 1249 |
|
1244 | 1250 | def __repr__(self) -> str: |
1245 | 1251 | return f'<IdentifiableAction name={self.name}, email={self.email}>' |
@@ -1277,16 +1283,16 @@ def text(self, text: str) -> None: |
1277 | 1283 |
|
1278 | 1284 | def __eq__(self, other: object) -> bool: |
1279 | 1285 | if isinstance(other, Copyright): |
1280 | | - return hash(other) == hash(self) |
| 1286 | + return self._text == other._text |
1281 | 1287 | return False |
1282 | 1288 |
|
1283 | 1289 | def __lt__(self, other: Any) -> bool: |
1284 | 1290 | if isinstance(other, Copyright): |
1285 | | - return self.text < other.text |
| 1291 | + return self._text < other._text |
1286 | 1292 | return NotImplemented |
1287 | 1293 |
|
1288 | 1294 | def __hash__(self) -> int: |
1289 | | - return hash(self.text) |
| 1295 | + return hash(self._text) |
1290 | 1296 |
|
1291 | 1297 | def __repr__(self) -> str: |
1292 | 1298 | return f'<Copyright text={self.text}>' |
0 commit comments