Skip to content

Should not throw "Value of type "Optional[Match[str]]" is not indexable" error when using Assignment expressions #8254

Closed
@dongweiming

Description

@dongweiming

I ’m not sure if it ’s mypy or typeshed issue.

I found an issue about this, here is a short example using Assignment expressions, it will throw an error:

cat a.py 
import re

if (m := re.search(".", "foo")):
    print(m[0])

❯ mypy a.py 
a.py:4: error: Value of type "Optional[Match[str]]" is not indexable
        print(m[0])
              ^
Found 1 error in 1 file (checked 1 source file)

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