Skip to content

Self revealed as Never yet invalid-return-type error is reported #1895

@stefanboca

Description

@stefanboca

Summary

In this example, ty reveals a type of Never for other in baz, but still reports an invalid-return-type error.

from typing import Self, final, reveal_type

@final
class Foo:
    def bar(self, other: Foo) -> bool:
        if isinstance(other, Foo): return True

    def baz(self, other: Self) -> bool:
        #                         ^^^^ Function can implicitly return `None`, which is not assignable to return type `bool` (invalid-return-type)
        if isinstance(other, Foo): return True
        reveal_type(other) # revealed: Never

basedpyright andmypyreport no errors on this code snippet.

https://play.ty.dev/866a48cf-0624-49ba-b1cf-fb57a57cfd76

Version

ty ruff/0.14.9+38 (4e1cf5747 2025-12-15)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions