We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
引用的文章在讨论新式类的MRO顺序。
在经典对象模型中,方法和属性的查找链是按照从左到右,深度优先的方式进行查找。所以当A的实例b 要使用属性a时,它的查找顺序为:A->B->D->C->A,这样做就会忽略类C的定义a,而先找到的基类D的 属性a,这是一个bug,这个问题在新式类中得到修复,新的对象模型采用的是从左到右,广度优先的方式 进行查找,所以查找顺序为A->B->C->D,可以正确的返回类C的属性a。
其中提到新式类是广度优先查找,这里明显错误。事实上Python在这里采用的是C3算法。
The text was updated successfully, but these errors were encountered:
广度优先是不对的,只有某些情况下采用C3算法的结果和广度优先遍历的结果一样。C3算法解决单调性和本地优先级的问题才提出的。
Sorry, something went wrong.
@sniperXue 嗯,是这样的。不过时隔一年作者也没有修正这个问题
广度优先确实不对 https://makina-corpus.com/blog/metier/2014/python-tutorial-understanding-python-mro-class-search-path
No branches or pull requests
引用的文章在讨论新式类的MRO顺序。
其中提到新式类是广度优先查找,这里明显错误。事实上Python在这里采用的是C3算法。
The text was updated successfully, but these errors were encountered: