`or` doesn't figure out that an `optional` on left hand side evaluates to right hand side
I would expect Optional[str] or str to have type str. It seems like or is handled correctly in many such situations, but not in this distilled (and thus slightly pointless) minimized repro case:
d = {'x': 'y'}
[(i or d.get('b') or i).strip() for i in ['x', 'y']]
$ pytype a.py
...
File "a.py", line 2, in <module>: No attribute 'strip' on None [attribute-error]
In Optional[str]
...
$ pytype --version
2020.08.10
simpler repro:
a = [(i or None) for i in ['x', 'y']]
reveal_type(a) # => List[Optional[str]]
@martindemello nice! But FWIW: I'm not entirely sure if it is the same problem. It is also a bit like an opposite problem, and it might be a different code path. Your example rely on knowing that the xy list not only is "str - not None" but also "str - not None and not empty". My example only rely on knowing that the xy list "str - not None but potentially empty" and that the computed list thus also is "str - not None but potentially empty" .
@kiilerix for i in ['x', 'y'] should make i strictly a str, not an Optional[str], and so i or ... should always be i