Skip to content

Flag None check on value that cannot be None #18386

Description

@nickdrozd

Say I have function that maybe returns None and I check the result:

deff() ->int|None: ...
iff() isNone: ...

I rewrite the function so that it never returns None:

deff() ->int: ...
iff() isNone: ...

Now the is None check makes no sense -- it will always fail. This is a mistake introduced in refactoring and it should be flagged. (And similar for is not None checks)

In Rust I don't think this kind of error is possible:

fnf() -> Option<u8>;iff().is_none(){}// okayfng() -> u8;ifg().is_none(){}// no good

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-reachabilityDetecting unreachable code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions