Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
dongweiming opened this issue Jan 7, 2020 · 2 comments

Comments

@dongweiming
Copy link

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)
@dongweiming dongweiming changed the title re's Match should not throw "Value of type "Optional[Match[str]]" is not indexable" error when using Assignment expressions Should not throw "Value of type "Optional[Match[str]]" is not indexable" error when using Assignment expressions Jan 7, 2020
@TH3CHARLie
Copy link
Collaborator

TH3CHARLie commented Jan 7, 2020

It is a mypy issue, related #7316

As a workaround, use:

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

@JelleZijlstra
Copy link
Member

Yes, this is a duplicate of #7316.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants