Description
foo: list[str] = ["a", "b"]
bar: list[str | float] = foo + ["c"] # incorrectly shows a type-widening error here
baz: list[str | float] = ["a", "b", "c"] # type-widening is correctly accepted here
bat: list[str | float] = foo # correctly shows a type-widening error here
The bar line should be treated as the baz, as list + list creates a new list with no other references to it; mutating bar does not/cannot affect foo.
Link to BasedPyright Playground Example
Occurs in Pyright as well; filed upstream as Pyright bug #10943.
Description
The
barline should be treated as thebaz, aslist + listcreates a new list with no other references to it; mutatingbardoes not/cannot affectfoo.Link to BasedPyright Playground Example
Occurs in Pyright as well; filed upstream as Pyright bug #10943.