Skip to content

map(str, cmd) fails with Sequence[str] & ~str, succeeds with Sequence[str] #2091

@carljm

Description

@carljm

From #2087:

from typing import Sequence, reveal_type

def test(command: Sequence[str] | str) -> str:
    reveal_type(command)  # Sequence[str]
    parts = map(str, command)  # works
    if isinstance(command, str):
        return command
    else:
        reveal_type(command)  # Sequence[str] & ~str
        parts = map(str, command)  # fails with "not assignable to `Iterable[Buffer]`"
        return ' '.join(parts)

print(test('echo hello'))
print(test(['echo', 'hello']))

The first map works, the second one fails; the only difference is the intersection with ~str. It should not be possible for that to cause the assignment to fail, if the other intersection component succeeds.

Metadata

Metadata

Assignees

Labels

genericsBugs or features relating to ty's generics implementationset-theoretic typesunions, intersections and more

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions