Skip to content

Type issue in a protocol method if ... is missing from the body #6487

@kkom

Description

@kkom

Describe the bug

Pyright finds an issue in the following code snippet:

from typing import Protocol

class Repro(Protocol):
    def foo(self) -> str:
        """docblock"""
error: Function with declared return type "str" must return value on all code paths
    "None" is incompatible with "str" (reportGeneralTypeIssues)

Things are fine if the code looks like this:

from typing import Protocol

class Repro(Protocol):
    def foo(self) -> str:
        """docblock"""
        ...

However after changes to PIE790 in Ruff v0.1.6, Ruff wants to remove the ... - resulting the Pyright error.

@zanieb from @astral-sh thinks that nothing in PEP 544 requires the ... and that Pyright shouldn't see a problem here. See astral-sh/ruff#8756 (comment)

@erictraut – what's your view? It would be great if Pyright and Ruff were to agree on what's legal here.

VS Code extension or command-line

Pyright 1.1.336 CLI

Metadata

Metadata

Assignees

No one assigned

    Labels

    as designedNot a bug, working as intendedbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions