Skip to content

python type annotations: use Mapping instead of Dict? #414

@lheckemann

Description

@lheckemann

The following code fails mypy type checking:

from lsprotocol.types import WorkspaceEdit, TextEdit, Range, Position
pos = Position(0, 0)
changes = {"file:///tmp/foo.txt": [TextEdit(Range(pos, pos), new_text="hello world")]}
WorkspaceEdit(changes=changes)

Because changes is a dict[str, list[TextEdit]] while WorkspaceEdit's changes expects a dict[str, Sequence[TextEdit]] and dict is invariant -- but we can't actually create a Sequence!

I think the type annotations should probably use Mapping instead of Dict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable buggood first issueGood for newcomershelp wantedIssues identified as good community contribution opportunitiesneeds PR

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions