github / github/codeql

LGTM.com - false positive: for python methods in diamond inheritance

Đang mở
#3,450 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
false-positive Python
Ngôn ngữ chính
CodeQL
Star
10.1k
Fork
2.1k
Merge trung bình
2 ngày 15 giờ
Pull request đã merge (30 ngày)
141

Mô tả

**Description of the false positive**

The short version of the code is:
```
from sympy import AtomicExpr, Basic

assert issubclass(AtomicExpr, Basic)

class _GradedSymbol(AtomicExpr):
pass

class _JoinedPrinterMixin(Basic):
pass

class BasisBaseSymbol(_GradedSymbol, _JoinedPrinterMixin):
pass
```
The resulting inheritance is a diamond,
```
BasisBaseSymbol -> _GradedSymbol -> AtomicExpr -> ... --> Basic
\ /
-> _JoinedPrinterMixin -------------/
```

The query that's failing is [Conflicting attributes in base classes
](https://lgtm.com/rules/7860084/).
LGTM claims that the classes have conflicting values for `_subs`, even though none of my classes define `_subs`, and the two classes which do are already subclasses of each other, so cannot be conflicting.

Error in context: https://lgtm.com/projects/g/pygae/galgebra/snapshot/aeee3eced507e24575c9ff9913abf79ff89ec5d2/files/galgebra/atoms.py?sort=name&dir=ASC&mode=heatmap#x2f5f31388b989ba7:1

The description of that query says:

> When a class subclasses multiple base classes, attribute lookup is performed from left to right amongst the base classes.

This text is not really accurate - the MRO may not be left to right at all, such as `class Child(Grandparent, Parent)`. Perhaps the implementation is therefore also wrong.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.