if any("__len__" in B.__dict__ for B in C.__mro__):
➊
return True
➋
return NotImplemented
➌
➊
如果
C.__mro__
列出的某个类(
C
及其超类)的
__dict__
中有名为
__len__
的属性……
➋
……就返回
True
,表明
C
是
Sized
的虚拟子类。
➌
否则,返回
NotImplemented
,让子类检查继续下去。
如果对子类检查的细节感兴趣,可以阅读
Python 3.6
中
ABCMeta.__subclasscheck__ ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month, and much more.