Return true if the object is an abstract base class (ABC).
(object)
| 452 | or isinstance(object, functools._singledispatchmethod_get)) |
| 453 | |
| 454 | def isabstract(object): |
| 455 | """Return true if the object is an abstract base class (ABC).""" |
| 456 | if not isinstance(object, type): |
| 457 | return False |
| 458 | if object.__flags__ & TPFLAGS_IS_ABSTRACT: |
| 459 | return True |
| 460 | if not issubclass(type(object), abc.ABCMeta): |
| 461 | return False |
| 462 | if hasattr(object, '__abstractmethods__'): |
| 463 | # It looks like ABCMeta.__new__ has finished running; |
| 464 | # TPFLAGS_IS_ABSTRACT should have been accurate. |
| 465 | return False |
| 466 | # It looks like ABCMeta.__new__ has not finished running yet; we're |
| 467 | # probably in __init_subclass__. We'll look for abstractmethods manually. |
| 468 | for name, value in object.__dict__.items(): |
| 469 | if getattr(value, "__isabstractmethod__", False): |
| 470 | return True |
| 471 | for base in object.__bases__: |
| 472 | for name in getattr(base, "__abstractmethods__", ()): |
| 473 | value = getattr(object, name, None) |
| 474 | if getattr(value, "__isabstractmethod__", False): |
| 475 | return True |
| 476 | return False |
| 477 | |
| 478 | def _getmembers(object, predicate, getter): |
| 479 | results = [] |
searching dependent graphs…