Copy state of old node to the new node. This handles cases where there is __dict__ and/or attribute descriptors (either from slots or because the type is defined in a C extension module). Assume that both objects have the same __class__.
(
new: object, old: object, copy_dict: bool = False, skip_slots: tuple[str, ...] = ()
)
| 388 | |
| 389 | |
| 390 | def replace_object_state( |
| 391 | new: object, old: object, copy_dict: bool = False, skip_slots: tuple[str, ...] = () |
| 392 | ) -> None: |
| 393 | """Copy state of old node to the new node. |
| 394 | |
| 395 | This handles cases where there is __dict__ and/or attribute descriptors |
| 396 | (either from slots or because the type is defined in a C extension module). |
| 397 | |
| 398 | Assume that both objects have the same __class__. |
| 399 | """ |
| 400 | if hasattr(old, "__dict__"): |
| 401 | if copy_dict: |
| 402 | new.__dict__ = dict(old.__dict__) |
| 403 | else: |
| 404 | new.__dict__ = old.__dict__ |
| 405 | |
| 406 | for attr in get_class_descriptors(old.__class__): |
| 407 | if attr in skip_slots: |
| 408 | continue |
| 409 | try: |
| 410 | if hasattr(old, attr): |
| 411 | setattr(new, attr, getattr(old, attr)) |
| 412 | elif hasattr(new, attr): |
| 413 | delattr(new, attr) |
| 414 | # There is no way to distinguish getsetdescriptors that allow |
| 415 | # writes from ones that don't (I think?), so we just ignore |
| 416 | # AttributeErrors if we need to. |
| 417 | # TODO: What about getsetdescriptors that act like properties??? |
| 418 | except AttributeError: |
| 419 | pass |
| 420 | |
| 421 | |
| 422 | def is_sub_path_normabs(path: str, dir: str) -> bool: |
no test coverage detected
searching dependent graphs…