Skip to content

pyright strict errors with pathspec >= 1.0.0 #101

@adamtheturtle

Description

@adamtheturtle

I use pyright with strict type checking in my project, where I also use pathspec. With recent pathspec versions I hit errors.

pyrightconfig.json:

{
  "typeCheckingMode": "strict"
}

example.py:

import pathspec

gitignore_patterns: list[str] = [".git", "*.pyc"]
spec = pathspec.PathSpec.from_lines(
    pattern_factory="gitignore",
    lines=gitignore_patterns,
)
result = spec.match_file(file="test.py")
> uv run --with="pyright" --with="pathspec==1.0.2" pyright example.py
/Users/adam/Desktop/example.py
  /Users/adam/Desktop/example.py:4:1 - error: Type of "spec" is unknown (reportUnknownVariableType)
  /Users/adam/Desktop/example.py:4:8 - error: Type of "from_lines" is partially unknown
    Type of "from_lines" is "(pattern_factory: str | ((AnyStr@from_lines) -> Pattern), lines: Iterable[AnyStr@from_lines], *, backend: str | None = None, _test_backend_factory: ((Sequence[Pattern]) -> _Backend) | None = None) -> Unknown" (reportUnknownMemberType)
  /Users/adam/Desktop/example.py:8:1 - error: Type of "result" is unknown (reportUnknownVariableType)
  /Users/adam/Desktop/example.py:8:10 - error: Type of "match_file" is unknown (reportUnknownMemberType)
4 errors, 0 warnings, 0 informations

With pathspec 0.12.1 there are no errors here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions