Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add stubs for ijson #13462

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
1 change: 1 addition & 0 deletions pyrightconfig.stricter.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"stubs/humanfriendly",
"stubs/hvac",
"stubs/icalendar",
"stubs/ijson",
"stubs/influxdb-client",
"stubs/jmespath",
"stubs/jsonschema",
Expand Down
3 changes: 3 additions & 0 deletions stubs/ijson/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = "3.3.*"
upstream_repository = "https://github.com/ICRAR/ijson"
requires = ["types-cffi"]
21 changes: 21 additions & 0 deletions stubs/ijson/ijson/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from ijson.common import IncompleteJSONError as IncompleteJSONError, JSONError as JSONError, ObjectBuilder as ObjectBuilder
from ijson.utils import coroutine as coroutine, sendable_list as sendable_list

from ._abstract_backend import _BackendModule
from .version import __version__ as __version__

def get_backend(backend: str) -> _BackendModule: ...

backend: _BackendModule = ...
basic_parse = backend.basic_parse
basic_parse_coro = backend.basic_parse_coro
parse = backend.parse
parse_coro = backend.parse_coro
items = backend.items
items_coro = backend.items_coro
kvitems = backend.kvitems
kvitems_coro = backend.kvitems_coro
basic_parse_async = backend.basic_parse_async
parse_async = backend.parse_async
items_async = backend.items_async
kvitems_async = backend.kvitems_async
19 changes: 19 additions & 0 deletions stubs/ijson/ijson/_abstract_backend.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from _typeshed import Incomplete
from types import ModuleType
from typing import type_check_only

@type_check_only
class _BackendModule(ModuleType):
basic_parse: Incomplete
basic_parse_coro: Incomplete
parse: Incomplete
parse_coro: Incomplete
items: Incomplete
items_coro: Incomplete
kvitems: Incomplete
kvitems_coro: Incomplete
basic_parse_async: Incomplete
parse_async: Incomplete
items_async: Incomplete
kvitems_async: Incomplete
backend: Incomplete
11 changes: 11 additions & 0 deletions stubs/ijson/ijson/backends/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from ctypes import CDLL

from _cffi_backend import Lib
from cffi import FFI

class YAJLImportError(ImportError): ...

def require_version(version: int, required: int) -> None: ...
def get_yajl_version(yajl: CDLL | Lib) -> int: ...
def find_yajl_ctypes(required: int) -> CDLL: ...
def find_yajl_cffi(ffi: FFI, required: int) -> Lib: ...
Empty file.
22 changes: 22 additions & 0 deletions stubs/ijson/ijson/backends/_yajl2_ctypes_common.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from _ctypes import Structure
from _typeshed import Incomplete
from ctypes import CDLL, _CFunctionType
from typing import ClassVar

C_EMPTY: type[_CFunctionType]
C_INT: type[_CFunctionType]
C_LONG: type[_CFunctionType]
C_LONGLONG: type[_CFunctionType]
C_DOUBLE: type[_CFunctionType]
C_STR: type[_CFunctionType]
YAJL_OK: int
YAJL_CANCELLED: int
YAJL_INSUFFICIENT_DATA: int
YAJL_ERROR: int

class _CallbacksStructure(Structure):
_fields_: ClassVar[list[tuple[str, type[_CFunctionType]]]]

def get_yajl(version: int) -> CDLL: ...
def make_callbaks(send: Incomplete, use_float: bool, yajl_version: int) -> _CallbacksStructure: ...
def yajl_get_error(yajl: Incomplete, handle, buffer) -> str | bytes | None: ...
27 changes: 27 additions & 0 deletions stubs/ijson/ijson/backends/python.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from _typeshed import Incomplete
from collections.abc import Generator
from re import Pattern
from typing import Literal

from ijson import common

inf = float("inf")
LEXEME_RE: Pattern[str]
UNARY_LEXEMES: set[str]
EOF: tuple[Literal[-1], None]

class UnexpectedSymbol(common.JSONError):
def __init__(self, symbol: str, pos: int) -> None: ...

def utf8_encoder(target: Incomplete) -> Generator[None, bytes]: ...
def Lexer(target: Generator[Incomplete, bytes]) -> Generator[None, tuple[int, str]]: ...
def parse_value(
target: Generator[Incomplete, tuple[str, object]], multivalue: bool, use_float: bool
) -> Generator[None, tuple[int, str | None]]: ...
def parse_string(symbol: str) -> str: ...
def basic_parse_basecoro(
target: Generator[None, tuple[int, str | None]],
multiple_values: bool = False,
allow_comments: bool = False,
use_float: bool = False,
) -> Generator[None, bytes]: ...
10 changes: 10 additions & 0 deletions stubs/ijson/ijson/backends/yajl.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from collections.abc import Generator
from ctypes import CDLL, Structure

yajl: CDLL

class Config(Structure): ...

def basic_parse_basecoro(
target, allow_comments: bool = False, multiple_values: bool = False, use_float: bool = False
) -> Generator[None, bytes]: ...
10 changes: 10 additions & 0 deletions stubs/ijson/ijson/backends/yajl2.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from _typeshed import Incomplete
from collections.abc import Generator

yajl: Incomplete
YAJL_ALLOW_COMMENTS: int
YAJL_MULTIPLE_VALUES: int

def basic_parse_basecoro(
target, allow_comments: bool = False, multiple_values: bool = False, use_float: bool = False
) -> Generator[None, Incomplete]: ...
14 changes: 14 additions & 0 deletions stubs/ijson/ijson/backends/yajl2_c.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from _typeshed import Incomplete

def basic_parse_basecoro(target, **kwargs): ...
def basic_parse_gen(file, **kwargs): ...
def basic_parse_async(file, **kwargs): ...
def parse_basecoro(target, **kwargs): ...
def parse_gen(file, **kwargs): ...
def parse_async(file, **kwargs): ...
def kvitems_basecoro(target, prefix, map_type: Incomplete | None = None, **kwargs): ...
def kvitems_gen(file, prefix, map_type: Incomplete | None = None, **kwargs): ...
def kvitems_async(file, prefix, map_type: Incomplete | None = None, **kwargs): ...
def items_basecoro(target, prefix, map_type: Incomplete | None = None, **kwargs): ...
def items_gen(file, prefix, map_type: Incomplete | None = None, **kwargs): ...
def items_async(file, prefix, map_type: Incomplete | None = None, **kwargs): ...
30 changes: 30 additions & 0 deletions stubs/ijson/ijson/backends/yajl2_cffi.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from _typeshed import Incomplete
from collections.abc import Generator

ffi: Incomplete
yajl: Incomplete
YAJL_OK: int
YAJL_CANCELLED: int
YAJL_INSUFFICIENT_DATA: int
YAJL_ERROR: int
YAJL_ALLOW_COMMENTS: int
YAJL_MULTIPLE_VALUES: int

def append_event_to_ctx(event): ...
def null() -> None: ...
def boolean(val): ...
def integer(val): ...
def double(val): ...
def number(val, length): ...
def string(val, length): ...
def start_map() -> None: ...
def map_key(key, length): ...
def end_map() -> None: ...
def start_array() -> None: ...
def end_array() -> None: ...
def yajl_init(scope, send, allow_comments: bool = False, multiple_values: bool = False, use_float: bool = False): ...
def yajl_parse(handle, buffer) -> None: ...

class Container: ...

def basic_parse_basecoro(target, **config) -> Generator[None, Incomplete]: ...
41 changes: 41 additions & 0 deletions stubs/ijson/ijson/benchmark.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from collections import OrderedDict
from collections.abc import Callable, Iterable
from typing_extensions import TypeAlias

from ijson._abstract_backend import _BackendModule

_Benchmark: TypeAlias = Callable[[int], bytes]

BACKEND_NAMES: tuple[str, ...]

def benchmark(f: _Benchmark) -> _Benchmark: ...
def long_list(n: int) -> bytes: ...
def big_int_object(n: int) -> bytes: ...
def big_decimal_object(n: int) -> bytes: ...
def big_null_object(n: int) -> bytes: ...
def big_bool_object(n: int) -> bytes: ...
def big_str_object(n: int) -> bytes: ...
def big_longstr_object(n: int) -> bytes: ...
def object_with_10_keys(n: int) -> bytes: ...
def empty_lists(n: int) -> bytes: ...
def empty_objects(n: int) -> bytes: ...
def parse_benchmarks(s: str) -> list[_Benchmark]: ...
def load_backends() -> OrderedDict[str, _BackendModule]: ...
def parse_backends(s: str) -> OrderedDict[str, _BackendModule]: ...

class progress_message:
message: str
def __init__(self, message: str) -> None: ...
def __enter__(self): ...
def __exit__(self, *args: object) -> None: ...

class AsyncReader:
data: bytes
def __init__(self, data: bytes) -> None: ...
async def read(self, n: int = -1): ...
def close(self) -> None: ...

def median(values: Iterable[int]) -> int: ...
def stats(values: Iterable[int]) -> int: ...
def run_benchmarks(args, benchmark_func: Callable[[int], bytes] | None = None, fname: str | None = None) -> None: ...
def main() -> None: ...
34 changes: 34 additions & 0 deletions stubs/ijson/ijson/common.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from _typeshed import Incomplete, ReadableBuffer, SupportsRead
from collections.abc import Callable, Generator, Iterable, MutableMapping
from decimal import Decimal
from typing_extensions import TypeGuard

class JSONError(Exception): ...
class IncompleteJSONError(JSONError): ...

def parse_basecoro(target: Generator[Incomplete, tuple[str, str, Incomplete]]) -> Generator[None, None, None]: ...

class ObjectBuilder:
value: Incomplete
containers: list[Callable[[object], object]]
map_type: type[MutableMapping[Incomplete, Incomplete]]
def __init__(self, map_type: type[MutableMapping[Incomplete, Incomplete]] | None = None) -> None: ...
key: Incomplete
def event(self, event: str, value: Incomplete) -> None: ...

def items_basecoro(
target: Generator[object, tuple[Incomplete, str, object]], prefix: Incomplete, map_type: Incomplete | None = None
) -> Generator[None, Incomplete]: ...
def kvitems_basecoro(target, prefix, map_type: Incomplete | None = None) -> Generator[None, Incomplete]: ...
def integer_or_decimal(str_value: str): ...
def integer_or_float(str_value: str) -> Decimal | int: ...
def number(str_value: str) -> int | float: ...
def file_source(f: SupportsRead[str] | SupportsRead[ReadableBuffer], buf_size: int = 65536) -> Generator[bytes]: ...
def is_awaitablefunction(func: Callable[..., Incomplete]) -> bool: ...
def is_async_file(f: Incomplete) -> bool: ...
def is_file(x: object) -> TypeGuard[SupportsRead[Incomplete]]: ...
def is_iterable(x: object) -> TypeGuard[Iterable[Incomplete]]: ...
def parse(events): ...
def kvitems(events, prefix, map_type: Incomplete | None = None): ...
def items(events, prefix, map_type: Incomplete | None = None): ...
def enrich_backend(backend: dict[str, Incomplete]) -> None: ...
8 changes: 8 additions & 0 deletions stubs/ijson/ijson/compat.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from _typeshed import SupportsRead

class utf8reader:
str_reader: SupportsRead[str]
def __init__(self, str_reader: SupportsRead[str]) -> None: ...
def read(self, n: int) -> bytes: ...

def bytes_reader(f: SupportsRead[str] | SupportsRead[bytes]) -> utf8reader: ...
4 changes: 4 additions & 0 deletions stubs/ijson/ijson/dump.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
HEADERS: dict[str, str]

def to_string(o: object) -> str: ...
def dump() -> None: ...
19 changes: 19 additions & 0 deletions stubs/ijson/ijson/utils.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from _typeshed import Incomplete
from collections.abc import Callable, Generator
from typing import Iterable, TypeVar
from typing_extensions import ParamSpec, TypeAlias

_P = ParamSpec("_P")
_T = TypeVar("_T")
_GS = TypeVar("_GS")
_GR = TypeVar("_GR")
_CoroPipelineArgs: TypeAlias = tuple[Callable[..., Incomplete], tuple[Incomplete, ...], dict[str, Incomplete]]

def coroutine(func: Callable[_P, Generator[_T, _GS, _GR]]) -> Callable[_P, Generator[_T, _GS, _GR]]: ...
def chain(sink: list[Incomplete], *coro_pipeline: _CoroPipelineArgs) -> list[Incomplete]: ...

class sendable_list(list[_T]):
# send = list.append
def send(self, object: _T, /) -> None: ...

def coros2gen(source: Iterable[_T], *coro_pipeline: _CoroPipelineArgs) -> Generator[_T, Incomplete, None]: ...
27 changes: 27 additions & 0 deletions stubs/ijson/ijson/utils35.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import collections
from _typeshed import Incomplete, SupportsRead
from collections.abc import Callable
from typing import TypeVar

from ijson import compat
from ijson.utils import _CoroPipelineArgs

_T = TypeVar("_T")

class utf8reader_async(compat.utf8reader):
async def read(self, n: int) -> bytes: ... # type: ignore[override]

class sendable_deque(collections.deque[_T]):
# send = collections.deque.append
def send(self, x: _T, /) -> None: ...

class async_iterable:
events: sendable_deque[Incomplete]
coro: list[Incomplete]
coro_finished: bool
f: SupportsRead[Incomplete]
buf_size: int
read: Callable[[int], bytes] | None
def __init__(self, f: SupportsRead[Incomplete], buf_size: int, *coro_pipeline: _CoroPipelineArgs) -> None: ...
def __aiter__(self): ...
async def __anext__(self): ...
1 change: 1 addition & 0 deletions stubs/ijson/ijson/version.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__: str
Loading