Skip to content

fix(typing): read_json's stub only allowed a single path, not a list - #577

Open
aleks-drozy wants to merge 1 commit into
duckdb:mainfrom
aleks-drozy:fix/read-json-accepts-list-of-paths-576
Open

fix(typing): read_json's stub only allowed a single path, not a list#577
aleks-drozy wants to merge 1 commit into
duckdb:mainfrom
aleks-drozy:fix/read-json-accepts-list-of-paths-576

Conversation

@aleks-drozy

Copy link
Copy Markdown

Summary

Fixes #576.

read_json accepts a list of paths at runtime (reading multiple newline-delimited JSON files as one relation), but the type stub only listed a single str | bytes | PathLike | IO. mypy and pyright both reject valid calls like:

con.read_json(["a.jsonl", "b.jsonl"], format="newline_delimited")

Fix

Widened path_or_buffer on read_json to also accept a Sequence of the same union, matching the exact pattern from_parquet / read_parquet / from_csv_auto already use in this same file. Applied to both the DuckDBPyConnection.read_json method stub and the module-level read_json wrapper stub, since both currently disagree with the runtime the same way.

Kept the diff minimal, on purpose: I noticed _duckdb-stubs/__init__.pyi has some pre-existing ruff findings (a few PYI021 docstrings, one PYI002) unrelated to this change, and deliberately left those alone rather than folding an unrelated cleanup into a typing bugfix PR.

Verification

Reproduced the exact snippet from #576 against the fixed stub:

  • mypy --strict: reports the argument-type error before the fix, zero errors after.
  • pyright: same result, zero errors after.

No runtime code changed, this is a stub-only fix, so I did not do a full C++ build for this PR.

read_json accepts a list of paths at runtime (e.g. reading several
newline-delimited JSON files as one relation), but the type stub only
listed a single str/bytes/PathLike/IO. mypy and pyright both reject
valid calls like con.read_json(["a.jsonl", "b.jsonl"]) as a result.

Widened path_or_buffer to also accept a Sequence of the same union,
matching the exact pattern already used by from_parquet/read_parquet
and from_csv_auto in this same file. Applied to both the
DuckDBPyConnection.read_json method and the module-level read_json
wrapper, since both stubs currently disagree with the runtime.

Verified with a copy of the repro from the issue: both mypy --strict
and pyright report zero errors against the corrected stub, versus the
reported error against the original.

Fixes duckdb#576
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

read_json accepts a list of paths at runtime but the type stub only allows a single path.

1 participant