python / python/mypy

Mypy signals error with Protocol and __rpow__ method with three arguments

Aperta
#10,786 5 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

bug good-first-issue topic-protocols
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Okay, this is a head-scratcher. 😕

To Reproduce

# test_case.py
from typing import Protocol, overload, runtime_checkable
@runtime_checkable
class PowableProto(Protocol):
    @overload
    def __pow__(self, other: "PowableProto") -> "PowableProto":
        ...
    @overload
    def __pow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto":  # <- fine
        ...
    @overload
    def __rpow__(self, other: "PowableProto") -> "PowableProto":
        ...
    @overload
    def __rpow__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto":  # <- this (of all things) breaks
        ...
    @overload
    def __rpOw__(self, other: "PowableProto") -> "PowableProto":
        ...
    @overload
    def __rpOw__(self, other: "PowableProto", modulo: "PowableProto") -> "PowableProto":  # <- fine
        ...
% mypy --version
mypy 0.910
% mypy --config-file=/dev/null test_case.py
/dev/null: No [mypy] section in config file
test_case.py:15: error: Invalid signature "def (test_case.PowableProto, test_case.PowableProto, test_case.PowableProto) -> test_case.PowableProto"
Found 1 error in 1 file (checked 1 source file)

Expected vs. Actual Behavior

I would expect at least consistent behavior among the overridden methods. This only crops up with __rpow__ for some reason. (I have tested many others.)

Your Environment

  • Mypy version used: 0.910
  • Mypy command-line flags: --config-file=/dev/null (i.e., force default configuration)
  • Mypy configuration options from mypy.ini (and other config files): N/A
  • Python version used: Python 3.9.6 (from python --version)
  • Operating system and version: Darwin Kernel Version 19.6.0: Thu May 6 00:48:39 PDT 2021; root:xnu-6153.141.33~1/RELEASE_X86_64 (from uname -v)

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia eseguendo il comando mypy fornito su test_case.py e confronta il modo in cui vengono gestiti gli overload a tre argomenti di pow e rpow. Segui la validazione della firma che produce l'errore, quindi rendi coerente il comportamento e verifica che il reproducer non segnali più una firma non valida.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.