Conversation
It is a pretty simple matter of pulling out the assignment target from the walrus. We don't bother handling things like `x := (y := z)` since I can't imagine they are common enough to be worth bothering but we could in the future if anyone cares. Fixes #8447.
mypy/checker.py
Outdated
| elif is_false_literal(node): | ||
| return None, {} | ||
| elif isinstance(node, CallExpr): | ||
| elif isinstance(node, CallExpr) and len(node.args) > 0: |
There was a problem hiding this comment.
Maybe instead add a separate 'if' statement under here that does if len(node.args) == 0: return {}, {}?
So that way, we don't have to do a bunch of extra isinstance(...) checks if the node happens to be an unrelated CallExpr.
| [builtins fixtures/f_string.pyi] | ||
|
|
||
| if (y := x) is not None: | ||
| reveal_type(y) # N: Revealed type is 'builtins.int' |
There was a problem hiding this comment.
Will 'x' also end up being narrowed here?
If it doesn't, I think it's probably fine for now, but we should probably file a follow-up task.
There was a problem hiding this comment.
No, but I think that's probably fine? I don't think it's actually idiomatic or makes sense to be using a walrus operator when the right hand side is a value.
There was a problem hiding this comment.
Hmm, that's true. I guess we can just not worry about it unless somebody brings it up.
Support narrowing of walrus in most cases (python#8458)
It is a pretty simple matter of pulling out the assignment target from the walrus. We don't bother handling things like `x := (y := z)` since I can't imagine they are common enough to be worth bothering but we could in the future if anyone cares. Fixes #8447.
It is a pretty simple matter of pulling out the assignment target from
the walrus. We don't bother handling things like
x := (y := z)sinceI can't imagine they are common enough to be worth bothering but we
could in the future if anyone cares.
Fixes #8447.