Skip to content

str.split v. LiteralString false positive type error. #1766

@rcls

Description

@rcls

Describe the Bug

This appears to be a false-positive type error from pyrefly. Using str.split on a LiteralString ends up with confusion between list[str] and list[LiteralString]:

ERROR sandbox.py:6:5-6: Argument list[LiteralString] is not assignable to parameter x with type list[str] in function foo [bad-argument-type]

def foo(x: list[str]) -> None:
    pass

l = 'a b c d'.split()
foo(l)

Sandbox Link

https://pyrefly.org/sandbox/?project=N4IgZglgNgpgziAXKOBDAdgEwEYHsAeAdAA4CeSIAOljGAARi64AU%2BidUEcALgNo8AnALoBKOgFoAfHQByudDETU6KusVRw41alDoBeOgHJUdbHQDGdTIcJxinbsxHVGLKM-QgANCACu3aDgSckQQAGI6AFUAh1IGX3RzAPktdGpMWgZcAQBbVG4AfXRfHOwYAVZ2CHRuMSk6QSV0VToBGG5fAWawShAZErKBdmB8AF9e6m8QMjawKFJCblwcqAoIgAVSWfmGjBwCC3lIAHNO-Ih5QmoIgGUYGDoAC25uYjhEAHoPmdp5wmzjh8YOgPphcOY4B9zEcIKcBOd5B8sgI6KgAG6oaCobCwQ7oE5nZLNXDEIlBahkbiPeTiNHlOAXZoGXoAZkIAEYAEwTTyjHyoJIQOkAMWgMAoaCweCIZBAoyAA

(Only applicable for extension issues) IDE Information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-discussionAn issue where it's not clear whether there is a bug or we are behaving as expected.typechecking

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions