Skip to content

Protocol definitions complain that "Function declared to return X but is missing an explicit return" #1916

@mgedmin

Description

@mgedmin

Describe the Bug

I have a Protocol defined like this:

class View(Protocol):
    """blah blah"""

    @property
    def sort_state(self) -> SortState:
        """Return the current sorting/grouping settings."""

and this causes pyrefly 0.46.0 to emit

ERROR Function declared to return `SortState` but is missing an explicit `return` [bad-return]
   --> src/.../views/base.py:206:29
    |
206 |     def sort_state(self) -> SortState:
    |                             ^^^^^^^^^

I expected no error (and the code is accepted fine by mypy and most other Python type checkers I've tested).

Sandbox Link

Here you are

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions