Skip to content

Regression for truthy bool with getattr #14480

Closed
@ilinum

Description

@ilinum

The following code generates an error on latest master but no on latest release (with --enable-error-codes=truthy-bool):

def f(obj: object) -> None:
    print("{}".format(
        getattr(type(obj), "__foo__", "") or "unknown"  # E: "builtins.getattr" returns "object" which does not implement __bool__ or __len__ so it could always be true in boolean context  [truthy-bool]
    ))

f("")

It's clearly a false positive, if your run the code you see that it prints unknown.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions