github / github/codeql

LGTM.com - false positive – too pedantic on Python structural typing / Protocol

オープン
#6,846 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る
false-positive
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 15時間
マージ済み PR(30日)
141

説明

LGTM is overly pedantic with Python's ``typing.Protocol``, i.e. structural typing, expecting it to be complete like a regular class.

------------

A ``Protocol`` is often used for type-hints of the *minimum* required functionality. In the false positive, a ``Protocol`` is used to express "can be compared by ``<``"; this is the minimum required to allow sorting:

> [The sort algorithm uses only `<` comparisons between items.](https://docs.python.org/3/library/functions.html#sorted)

> [The sort routines are guaranteed to use `__lt__()` when making comparisons between two objects.](https://docs.python.org/3/howto/sorting.html#odd-and-ends)

So the entire purpose of the ``Protocol`` is just to express the *minimum* not *complete* functionality.

LGTM instead treats this ``Protocol`` as a regular class and warns because it expects the *complete* set of comparison operators.

https://lgtm.com/projects/g/maxfischer2781/asyncstdlib/snapshot/cac1578bed589b6d1d858ec05441edb1a9756407/files/asyncstdlib/_typing.py?sort=name&dir=ASC&mode=heatmap#x5f23fe7abe3304d0:1

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。