Skip to content

--strict-optional Doesn't consider cases missing return  #2366

Closed
@rowillia

Description

@rowillia
def foo(a: bool) -> str:
    if a:
        return 'Hello world'

Type checks cleanly with --strict-optional but will return None in cases where a is False. This function should have to have a type signature of (bool) -> Optional[str].

I recently came across the --warn-no-return flag in #1748 . Is the intention is to force all code paths in functions to hit a return statement? I know that'd be more in line with PEP 8, but unfortunately I've got tons of code that relies on the absence of a return statement implying return None that I'd like to typecheck.

If this isn't a bug, I would suggest we change this to "--strict-optional should imply --warn-no-return".

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions