Skip to content

[invalid-return-type] should not be emitted on function definitions inside if TYPE_CHECKING blocks #339

@AlexWaygood

Description

@AlexWaygood

Summary

It's fairly common for .py files to have "stub-like sections" of code that are added just for a type checker's benefit. These "stub-like sections" generally do not have any function bodies (just ...), and are generally guarded by if TYPE_CHECKING. As an example, see this code in the trio library: https://github.com/python-trio/trio/blob/ac7b93f05796d49f324b231b3b2751facd34bc3a/src/trio/_file_io.py#L300-L344.

We shouldn't emit invalid-return-type for functions like this that are inside if TYPE_CHECKING blocks; we should omit checking these functions for that lint, just like we do for actual stub files.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinghelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions