Skip to content

Output type of warnings.catch_warnings with record=True #3463

Closed
@mslapek

Description

@mslapek

Although warnings.catch_warnings with record=True returns
a list, mypy is not aware of that:

File foo.py:

import warnings

with warnings.catch_warnings(record=True) as w:
    print(len(w))

Command mypy foo.py gives:

$ mypy foo.py
foo.py:4: error: Argument 1 to "len" has incompatible type "Optional[List[_Record]]"; expected "Sized"
Found 1 error in 1 file (checked 1 source file)

Using recent mypy from master (0.750+dev.e97377c454a1d5c019e9c56871d5f229db6b47b2).


I've attached PR fixing this #3464.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions