Skip to content

Confusing error message: Returned type () -> int is not assignable to declared return type () -> int #3810

Description

@amas127

Describe the Bug

import typing as tp

def integer_factory() -> int:
    return 1

class A:
    _factory: tp.ClassVar[tp.Callable[[], int]] = integer_factory

    @property
    def factory(self) -> tp.Callable[[], int]:
        return self._factory  # Pyrefly [bad-return]: Returned type `() -> int` is not assignable to declared return type `() -> int`

The title writes itself. A class variable typed as ClassVar obscures pyrefly correctly detect the type when returned with @property descriptor. When ClassVar denotion was removed, the error messages was gone. Even so, ClassVar should make no effects in this scenario and this possibly is a bug.

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIEAtsbgE4AuABA6cROgOZOpwvEAddEKGYYYJhwYxOMOgH0wqAMYN6pABQBKJgFoAfJPQNEQpuaZ0YDAK510TAIwjh6ZVF58AgqYcXFKmp0pIj8hADCHnBwAGqodADaDMQRqFAe2LAJCQC6ADRGDDk5TAC8hTJyAarqLhZMAALEdLjEcqxmFmISSjXBGnAwUGA6BmHhaRlZuQVSOb719Va29kyDw4TVQaRCIHkgZFZgUKSEalRQFADETAAKpEcnaxg4BEzKuOiQnHaoDBCfQhCG4AZRgMCYAAsGMk4IgAPTww7iE6EeiceEwdDwzC4ZRweEfL4QH50P4A7FMMD0HgAN1Q0FQmQhRO%2Bv3%2BnyYrQ56DgQPQZAYkM%2BulpcjgFLKTAEIAAzIRHAAmGVCBJyFp0OA5IQ2dDUWiMGCYXSYCBWVQQMVSgDkJPQ9Bg1qE9oYuisAEcbGajboANYwUi6FTKeB8crWgDu8XQTvQIAAvvtApaYAAxaAwChoLB4IhkBNAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

Labels

help wantedLarger than "good first issue", but still well-defined and ready for someone to pick upreadabilitytypechecking

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions