Skip to content

Support narrowing on attribute and subscript expressions #164

@dhruvmanila

Description

@dhruvmanila

Currently, red-knot only supports narrowing on a name expression like x but not on attributes (foo.x) or subscripts (foo[0]).

For example the following is a false negative as detected in astral-sh/ruff#16888 (comment):

from typing import Callable, Optional


class Config:
    formatting_function: Optional[Callable[[], None]] = None


def process(config: Config):
    reveal_type(config.formatting_function)  # revealed: () -> None | None
    if config.formatting_function:
        # red-knot: Object of type `None` is not callable [lint:call-non-callable]
        config.formatting_function()

Metadata

Metadata

Assignees

Labels

attribute accessInstance attributes, class attributes, etc.narrowingrelated to flow-sensitive type narrowing

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions