fix(typing): read_json's stub only allowed a single path, not a list - #577
Open
aleks-drozy wants to merge 1 commit into
Open
fix(typing): read_json's stub only allowed a single path, not a list#577aleks-drozy wants to merge 1 commit into
aleks-drozy wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #576.
read_jsonaccepts a list of paths at runtime (reading multiple newline-delimited JSON files as one relation), but the type stub only listed a singlestr | bytes | PathLike | IO. mypy and pyright both reject valid calls like:Fix
Widened
path_or_bufferonread_jsonto also accept aSequenceof the same union, matching the exact patternfrom_parquet/read_parquet/from_csv_autoalready use in this same file. Applied to both theDuckDBPyConnection.read_jsonmethod stub and the module-levelread_jsonwrapper stub, since both currently disagree with the runtime the same way.Kept the diff minimal, on purpose: I noticed
_duckdb-stubs/__init__.pyihas some pre-existing ruff findings (a fewPYI021docstrings, onePYI002) 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.