Skip to content

Typechecking differs between one-line def of "return expr" vs. "r = expr; return r" #11985

Description

@drvink

mypy 0.931

#!/usr/bin/env python3fromcollections.abcimportIterablefromtypingimportOptionalimportosdefmin_direntry_good(
fs: 'Iterable[os.DirEntry[str]]'
) ->'Optional[os.DirEntry[str]]':
r=min(fs, default=None, key=lambdax: x.stat().st_mtime)
returnrdefmin_direntry_bad(
fs: 'Iterable[os.DirEntry[str]]'
) ->'Optional[os.DirEntry[str]]':
returnmin(fs, default=None, key=lambdax: x.stat().st_mtime)
hober.py:16: error: Item "None" of "Optional[DirEntry[str]]" has no attribute "stat"
Found 1 error in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongtopic-type-contextType context / bidirectional inference

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions