python / python/mypy

MyPy treats `Placeholder` as `_PlaceholderType`

Offen
#21,313 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug topic-plugins
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug Report

Python 3.14 introduced functools.Placeholder so that you can create functions with partial() that choose which position arguments are filled in and which are passed through. However, MyPy rejects the typing of these values.

To Reproduce

From the docs

from functools import partial, Placeholder as _
remove = partial(str.replace, _, _, '')

Expected Behavior

MyPy recognises remove as partial function that takes two strings (the placeholders), accepts the placeholders as being placeholders for string variables, and the checks pass.

Actual Behavior

example.py:2: error: Argument 1 to "replace" of "str" has incompatible type "_PlaceholderType"; expected "str"  [arg-type]
example.py:2: error: Argument 2 to "replace" of "str" has incompatible type "_PlaceholderType"; expected "str"  [arg-type]
Found 2 errors in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 1.19.1
  • Mypy command-line flags: mypy example.py
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.14

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Führe zunächst die im Issue angegebene Reproduktion mypy example.py mit Python 3.14 aus und untersuche, wie functools.Placeholder typisiert und von der Analyse partieller Funktionen behandelt wird. Als erledigt gilt die Aufgabe, wenn das Beispiel beide Platzhalter als String-Positionen akzeptiert, ohne die gemeldeten arg-type-Fehler.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

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

Neue Issues direkt in Ihr Postfach

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