| 1141 | dispatch[set] = save_set |
| 1142 | |
| 1143 | def save_frozenset(self, obj): |
| 1144 | save = self.save |
| 1145 | write = self.write |
| 1146 | |
| 1147 | if self.proto < 4: |
| 1148 | self.save_reduce(frozenset, (list(obj),), obj=obj) |
| 1149 | return |
| 1150 | |
| 1151 | write(MARK) |
| 1152 | try: |
| 1153 | for item in obj: |
| 1154 | save(item) |
| 1155 | except BaseException as exc: |
| 1156 | exc.add_note(f'when serializing {_T(obj)} element') |
| 1157 | raise |
| 1158 | |
| 1159 | if id(obj) in self.memo: |
| 1160 | # If the object is already in the memo, this means it is |
| 1161 | # recursive. In this case, throw away everything we put on the |
| 1162 | # stack, and fetch the object back from the memo. |
| 1163 | write(POP_MARK + self.get(self.memo[id(obj)][0])) |
| 1164 | return |
| 1165 | |
| 1166 | write(FROZENSET) |
| 1167 | self.memoize(obj) |
| 1168 | dispatch[frozenset] = save_frozenset |
| 1169 | |
| 1170 | def save_global(self, obj, name=None): |