Skip to content

Make @cached_property generic over the value #2113

@srittau

Description

@srittau

Currently the following code will infer type Any for Foo().bar, although it should infer type str:

from werkzeug.utils import cached_property

class Foo:
    @cached_property
    def bar(self) -> str:
        return ""

reveal_type(Foo().bar)

Making class cached_property generic over the value solves this problem and corrects the type of a few fields like Request.base_url. I have a PR ready for this that actually removes a few instances of # type: ignore in werkzeug code (although it adds two new ones.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions