-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Incorrect union narrowing in expression with assignments #8128
Comments
@JukkaL @ilevkivskyi Jukka, Ivan, sorry for summoning you explicitly, but do you guys think you could take a look at this? This really blocks us on a few things... :( |
@1st1 I realize that this could be painful, but for the provided example, a simple refactor to f = foo()
if (f is None or f.lower()):
pass works as expected. If you have another example where it would be difficult or impossible to work around, we can bump the priority. Also I believe @Michael0x2a has been working on type narrowing the most recently. |
@ethanhs For some background, we have a lot of code that basically does this: if is_foo(obj):
obj.method() Where if foo := is_foo(obj):
foo.method() The workaround you suggest does not work as easily when the conditional is part of some long chain of |
Yeah, the workaround is obvious in simple cases. Take a look at @elprans' explanation of how we want to use walrus/mypy in our EdgeDB codebase. Would be amazing if you could bump the priority as having this fixed can simplify our code quite a bit. |
Just to double-check, did you try it on master? There is a chance #8258 fixed this. In any case, unfortunately I will not have time to work on this. |
@ilevkivskyi #8258 does seem to solve the simple case in #8128 (comment), but not the original issue reported here. |
This appears to have been fixed in #8458 (at least the original issue). |
Confirmed as fixed. |
bug.py:
The text was updated successfully, but these errors were encountered: