What happens?
When type checking the program below, which invokes read_json() on a StringIO, e.g. with pyright, errors like the following are produced:
/path/to/foobar.py:8:22 - error: Argument of type "StringIO" cannot be assigned to parameter "path_or_buffer" of type "str | bytes | PathLike[str]" in function "read_json"
Type "StringIO" is not assignable to type "str | bytes | PathLike[str]"
"StringIO" is not assignable to "str"
"StringIO" is not assignable to "bytes"
"StringIO" is incompatible with protocol "PathLike[str]"
"__fspath__" is not present (reportArgumentType)
…
Since duckdb/duckdb#13040 the read_json() methods can also read from file-like objects. Akin to #279, the read_json() stubs in _duckdb-stubs/__init__.pyi also need to have … | typing.IO[bytes] or similar added to the acceptable types for their path_or_buffer parameters.
To Reproduce
import duckdb
from io import StringIO
def foo():
text = StringIO()
text.write('["hello", "world"]')
duckdb.read_json(text)
duck = duckdb.connect()
duck.read_json(text)
Run this through a type-checker, e.g., pyright.
OS:
macOS arm64
DuckDB Package Version:
1.4.4 and the current main branch
Python Version:
3.14
Full Name:
John Marshall
Affiliation:
Centre for Population Genomics
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a stable release
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
Did you include all relevant configuration to reproduce the issue?
What happens?
When type checking the program below, which invokes
read_json()on aStringIO, e.g. with pyright, errors like the following are produced:Since duckdb/duckdb#13040 the
read_json()methods can also read from file-like objects. Akin to #279, theread_json()stubs in_duckdb-stubs/__init__.pyialso need to have… | typing.IO[bytes]or similar added to the acceptable types for theirpath_or_bufferparameters.To Reproduce
Run this through a type-checker, e.g.,
pyright.OS:
macOS arm64
DuckDB Package Version:
1.4.4 and the current main branch
Python Version:
3.14
Full Name:
John Marshall
Affiliation:
Centre for Population Genomics
What is the latest build you tested with? If possible, we recommend testing with the latest nightly build.
I have tested with a stable release
Did you include all relevant data sets for reproducing the issue?
Yes
Did you include all code required to reproduce the issue?
Did you include all relevant configuration to reproduce the issue?