False positive Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"

Offen
#7,192 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
python
Bereich
devtools

Rechercherichtung

Beginne mit dem minimalen Python-Repro und der gezeigten typeshed-Signatur von Message.get unter Verwendung von mypy 0.711, Python 3.6.7 und den aufgeführten mypy-Flags. Vergleiche die beiden gemeldeten False Positives mit dem erwarteten Verhalten ohne Fehler und verfolge anschließend den Pfad der Typprüfung, der den get-Aufruf und den booleschen Ausdruck behandelt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug priority-1-normal topic-type-variables

Note: I wasn't sure what a proper title was for this issue, so I chose one that is specific to the issue at hand. I checked typeshed, it looks like the issue is about mypy, not typeshed. I wouldn't be surprised if an issue already existed for this false positive.

Minimal repro:

assert isinstance(email, EmailMessage)

# Fine
r1 = email.get("List-Id", "")
# Fine
r2 = email.get("List-Id", "") or email.get("List-Unsubscribe", "")
# Fine
r3 = bool(email.get("List-Id", "") or email.get("List-Unsubscribe", ""))
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r4 = bool(
    email.get("Auto-Submitted", "") in ("no", "")
    or email.get("List-Unsubscribe", "")
)
# FAILS: Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"
r5 = email.get("Auto-Submitted", "") in ("no", "") or email.get(
    "List-Unsubscribe", ""
)

Both are false positives.

Typeshed:

_T = TypeVar('_T')

class Message:
    ...
    def get(self, name: str, failobj: _T = ...) -> Union[_HeaderType, _T]: ...
  • What is the actual behavior/output? Argument 2 to "get" of "Message" has incompatible type "str"; expected "bool"

  • What is the behavior/output you expect? No error.

  • What are the versions of mypy and Python you are using? mypy 0.711, Python 3.6.7
    Do you see the same issue after installing mypy from Git master? haven't tried it but since 0.711 is fairly recent...

  • What are the mypy flags you are using? (For example --strict-optional)

[mypy]
ignore_missing_imports = True
follow_imports = skip
check_untyped_defs = False
strict_equality = True
disallow_incomplete_defs = True
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
Ø Merge
1 T. 18 Std.
Gemergte PRs (30 T.)
54

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus python/mypy

Alle Issues in python/mypy

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.