File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
python/ql/lib/semmle/python/dataflow/new/internal Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -679,6 +679,7 @@ Class getADirectSubclass(Class cls) { cls = getADirectSuperclass(result) }
679
679
* For more info on the C3 MRO used in Python see:
680
680
* - https://docs.python.org/3/glossary.html#term-method-resolution-order
681
681
* - https://www.python.org/download/releases/2.3/mro/
682
+ * - https://opendylan.org/_static/c3-linearization.pdf
682
683
*/
683
684
private Class getNextClassInMro ( Class cls ) {
684
685
// class A(B, ...):
@@ -693,13 +694,21 @@ private Class getNextClassInMro(Class cls) {
693
694
sub .getBase ( i + 1 ) = classTracker ( result ) .asExpr ( ) and
694
695
not result = cls
695
696
)
696
- // There are two important properties for MRO computed with C3 in Python:
697
+ // There are three important properties for MRO computed with C3 in Python:
697
698
//
698
699
// 1) monotonicity: if C1 precedes C2 in the MRO of C, then C1 precedes C2 in the MRO
699
700
// of any subclass of C.
700
701
// 2) local precedence ordering: if C1 precedes C2 in the list of superclasses for C,
701
702
// they will keep the same order in the MRO for C (and due to monotonicity, any
702
703
// subclass).
704
+ // 3) consistency with the extended precedence graph: if A and B (that are part of the
705
+ // class hierarchy of C) do not have a subclass/superclass relationship on their
706
+ // own, the ordering of A and B in the MRO of C will be determined by the local
707
+ // precedence ordering in the classes that use both A and B, either directly or
708
+ // through a subclass. (see paper for more details)
709
+ //
710
+ // Note that not all class hierarchies are allowed with C3, see the Python 2.3 article
711
+ // for examples.
703
712
}
704
713
705
714
/**
You can’t perform that action at this time.
0 commit comments