Skip to content

False positive E1136 – unsubscriptable-object #10455

@Paulchen5

Description

@Paulchen5

Bug description

This is fine:

end_of_good_plan = good_case_plan_structures.get("<key>", None)
end_of_bad_plan = bad_case_plan_structures.get("<key>", None)

if end_of_good_plan is not None and end_of_bad_plan is not None:
    end_of_good_plan[0]

This throws an error:

end_of_good_plan = (
    good_case_plan_structures["<key>"]
    if "<key>" in good_case_plan_structures
    else None
)
end_of_bad_plan = (
    bad_case_plan_structures["<key>"]
    if "<key>" in bad_case_plan_structures
    else None
    )

if end_of_good_plan is not None and end_of_bad_plan is not None:
    end_of_good_plan[0]

Useful type hints:
(variable) good_case_plan_structures: dict[str | None, list[SecretClass]]
(variable) bad_case_plan_structures: dict[str | None, list[SecretClass]]

Configuration

default configuration

Command used

`pylint --disable fixme . `

Pylint output

************* Module src.****.****
src/****/****.py:****:****: E1136: Value 'end_of_good_plan' is unsubscriptable (unsubscriptable-object)

Expected behavior

No error because it's type is being checked

Pylint version

pylint 3.3.7
astroid 3.3.10
Python 3.12.0 (main, Dec 23 2024, 00:59:44) [Clang 16.0.0 (clang-1600.0.26.4)]

OS / Environment

macOS 15.5, zsh terminal with oh-my-zsh and p10k theme

Additional dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    False Positive 🦟A message is emitted but nothing is wrong with the codeNeeds PRThis issue is accepted, sufficiently specified and now needs an implementationinference

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions