-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
re's Match does not support indexing: "Value of type "Optional[Match[str]]" is not indexable" #3010
Comments
That's because of the Optional part. It's telling you that if there is no match, this code will break. Mypy will show no errors if you first check that |
@JelleZijlstra |
@JelleZijlstra if use
|
This is a mypy problem: from typing import Optional
def foo() -> Optional[str]:
pass
x = foo()
if x:
x.lower() # no error
if (y := foo()):
y.lower() # error: Item "None" of "Optional[str]" has no attribute "lower" (mypy 0.761 with Python 3.8.0) |
Yes, python/mypy#7316. |
The following is valid, but mypy complains about it:
Seems to be similar to #2751 (#2753).
mypy 0.710+dev.5f08ccf029aa3046b15e1afc60743ba692e4758d.dirty
(dirty due to using latest typshed master (53500c8)The text was updated successfully, but these errors were encountered: