-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
- Are you reporting a bug, or opening a feature request?
Bug
- Please insert below the code you are checking with mypy,
or a mock-up repro if the source is private. We would appreciate
if you try to simplify your case to a minimal repro.
from typing import Protocol
class Person(Protocol):
first_name: str
def greeting(self, message: str) -> str:
...
class FrenchPerson(Person):
prenom: str
def __init__(self, name: str):
self.prenom = name
def salutation(self, message: str) -> str:
return f"{message} {self.prenom}"
def print_person(person: Person) -> str:
return person.greeting(message="Je m'appelle")
def main():
fp = FrenchPerson(name='Henri')
response = print_person(fp)
print(response)- What is the actual behavior/output?
PEP 544 says you can state that an implementation supports a protocol by
subclassing the protocol.
It also says: "If one omits Protocol in the base class list, this would
be a regular (non-protocol) class that must implement Sized."
- What is the behavior/output you expect?
I would hope mypy would, either at declaration time or in the print_person function, spot that something claimed to be a Person but had neither the protocol variable name nor the method greeting.
It's also a shame that FrenchPerson got the greeting method added to it from the subclassing.
- What are the versions of mypy and Python you are using?
mypy 0.770 and Python 3.8.1
- What are the mypy flags you are using? (For example --strict-optional)
None.
louwers, andrija, ktbarrett and RunOrVeith