No error on missing method in Protocol subclass
Describe the bug
If a typing.Protocol defines a method with ..., I expect any implementations of that protocol to actually provide a concrete implementation of that method. But even if the implementation explicitly sub-classes the protocol (not typing.Protocol itself), pyright does not show an error
Code or Screenshots
from typing import Protocol
class MyProtocol(Protocol):
def name(self) -> str: ...
class MyImplementation(MyProtocol):
def __init__(self):
pass
# no implemetation of "name", but pyright does not show error even with strict type-checking
VS Code extension or command-line I'm running pyright 1.1.414 as a language server with neovim
possibly a duplicate of https://github.com/microsoft/pyright/issues/7545
Duplicate of #7545.
This is the same missing-method case discussed there: an explicit subclass inherits an ellipsis-bodied protocol method without implementing it, but the example never instantiates the subclass. Pyright treats that subclass as abstract for type-checking purposes rather than requiring it to be concrete at its declaration. It could be an intermediate base whose subclasses provide name. Adding __init__ doesn't change that, and strict mode doesn't make an abstract class declaration an error. That's the distinction behind the maintainer explanation in #7545.
I can see why that's surprising when you intended MyImplementation to be concrete: there's no immediate feedback that name is still missing. Pyright reports the missing implementation when you try to instantiate the class. If it's intended to be a concrete leaf that won't be subclassed, marking it @final also gives you a declaration-time error. These are static checking rules, not a claim that Python itself prevents construction of this undecorated example.