(obj, result=None, exclude=None)
| 267 | |
| 268 | |
| 269 | def object_to_dict(obj, result=None, exclude=None): |
| 270 | if result is None: |
| 271 | result = {} |
| 272 | exclude = DEFAULT_EXCLUDE.union(exclude or set()) |
| 273 | for attr in dir(obj): |
| 274 | if attr in exclude: |
| 275 | continue |
| 276 | try: |
| 277 | if not attr.startswith("_") and not callable(getattr(obj, attr)): |
| 278 | attr_value = getattr(obj, attr) |
| 279 | if "real" in dir(attr_value): |
| 280 | attr_value = attr_value.real |
| 281 | if attr == "size" and isinstance(attr_value, int): |
| 282 | attr_value = Length(attr_value).pt |
| 283 | |
| 284 | if is_primitive(attr_value): |
| 285 | result[attr] = attr_value |
| 286 | except: |
| 287 | pass |
| 288 | return result |
| 289 | |
| 290 | |
| 291 | def merge_dict(d1: dict, d2: list[dict]): |
no test coverage detected