Skip to content

Split error for empty function body into its own error code #1922

@AlexWaygood

Description

@AlexWaygood

Pyright allows functions to unsoundly have empty bodies even if they have a non-None return type, and mypy used to allow this too. As a result, we've seen several instances of users being confused by the fact that we do not allow this. For example:

def foo() -> int: ...  # error[invalid-return-type]

It's a deliberate decision from us to be more strict than pyright here, since this function obviously does not return an int at runtime. We already have a subdiagnostic message that explains the specific conditions in which we do allow functions to have empty bodies. However, splitting this into a separate empty-body error code would allow users who are heavily impacted by this inconsistency to switch it off on their codebase (even just temporarily while they work down the number of errors). This would also match mypy's behaviour (mypy has a dedicated empty-body error code.

Metadata

Metadata

Assignees

Labels

diagnosticsRelated to reporting of diagnostics.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions