Get unbound method for given bound method. Returns None if cannot get unbound method, or method is already unbound.
(func: Callable)
| 66 | |
| 67 | |
| 68 | def _unbind_method(func: Callable) -> Union[Callable, None]: |
| 69 | """Get unbound method for given bound method. |
| 70 | |
| 71 | Returns None if cannot get unbound method, or method is already unbound. |
| 72 | """ |
| 73 | owner = getattr(func, "__self__", None) |
| 74 | owner_class = type(owner) |
| 75 | name = getattr(func, "__name__", None) |
| 76 | instance_dict_overrides = getattr(owner, "__dict__", None) |
| 77 | if ( |
| 78 | owner is not None |
| 79 | and name |
| 80 | and ( |
| 81 | not instance_dict_overrides |
| 82 | or (instance_dict_overrides and name not in instance_dict_overrides) |
| 83 | ) |
| 84 | ): |
| 85 | return getattr(owner_class, name) |
| 86 | return None |
| 87 | |
| 88 | |
| 89 | @undoc |
no outgoing calls
searching dependent graphs…