From 03de19232ad6488d1251a03515c3918f78f88f08 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:03:01 +0200 Subject: [PATCH 1/2] Add stub file --- jq.pyi | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ py.typed | 0 setup.py | 2 +- 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 jq.pyi create mode 100644 py.typed diff --git a/jq.pyi b/jq.pyi new file mode 100644 index 0000000..9f71d17 --- /dev/null +++ b/jq.pyi @@ -0,0 +1,87 @@ +from collections.abc import Iterable +from typing import Any, Literal, overload + +from typing_extensions import Self, TypeAlias, deprecated + +JSON: TypeAlias = Any + +class _EmptyValue: ... + +_NO_VALUE: _EmptyValue + +class _JqStatePool: + def __init__(self, program_bytes: bytes, args: Any) -> None: ... + +class _Program: + def __init__(self, program_bytes: bytes, args: Any) -> None: ... + @overload + def input(self, value: JSON, text: _EmptyValue = _NO_VALUE) -> _ProgramWithInput: ... + @overload + def input(self, value: _EmptyValue = _NO_VALUE, *, text: str) -> _ProgramWithInput: ... + def input_value(self, value: JSON) -> _ProgramWithInput: ... + def input_values(self, values: Iterable[JSON]) -> _ProgramWithInput: ... + def input_text(self, text: str, *, slurp: bool = False) -> _ProgramWithInput: ... + @property + def program_string(self) -> str: ... + def __repr__(self) -> str: ... + @overload + @deprecated("'transform' is kept for 0.1.x backwards compatibility") + def transform( + self, + value: JSON | _EmptyValue = _NO_VALUE, + text: JSON | _EmptyValue = _NO_VALUE, + *, + text_output: Literal[True], + multiple_output: Literal[False] = False, + ) -> str: ... + @overload + @deprecated("'transform' is kept for 0.1.x backwards compatibility") + def transform( + self, + value: JSON | _EmptyValue = _NO_VALUE, + text: JSON | _EmptyValue = _NO_VALUE, + *, + text_output: Literal[False] = False, + multiple_output: Literal[True], + ) -> list[JSON]: ... + @overload + @deprecated("'transform' is kept for 0.1.x backwards compatibility") + def transform( + self, + value: JSON | _EmptyValue = _NO_VALUE, + text: JSON | _EmptyValue = _NO_VALUE, + text_output: Literal[False] = False, + multiple_output: Literal[False] = False, + ) -> JSON: ... + +class _ProgramWithInput: + def __init__(self, jq_state_pool: _JqStatePool, bytes_input: bytes, *, slurp: bool) -> None: ... + def __iter__(self) -> _ResultIterator: ... + def text(self) -> str: ... + def all(self) -> list[JSON]: ... + def first(self) -> JSON: ... + +class _ResultIterator: + def __init__(self, jq_state_pool: _JqStatePool, bytes_input: bytes, *, slurp: bool) -> None: ... + def __iter__(self) -> Self: ... + def __next__(self) -> JSON: ... + +def compile(program: str, args: Any | None = None) -> _Program: ... +@overload +def all(program: str, value: JSON, text: _EmptyValue = _NO_VALUE) -> list[JSON]: ... +@overload +def all(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> list[JSON]: ... +@overload +def first(program: str, value: JSON, text: _EmptyValue = _NO_VALUE) -> JSON: ... +@overload +def first(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> JSON: ... +@overload +def iter(program: str, value: JSON, text: _EmptyValue = _NO_VALUE) -> _ResultIterator: ... +@overload +def iter(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> _ResultIterator: ... +@overload +def text(program: str, value: JSON, text: _EmptyValue = _NO_VALUE) -> str: ... +@overload +def text(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> str: ... +@deprecated("'jq' is kept for 0.1.x backwards compatibility") +def jq(program: str) -> _Program: ... diff --git a/py.typed b/py.typed new file mode 100644 index 0000000..e69de29 diff --git a/setup.py b/setup.py index b00b35d..5bf6573 100644 --- a/setup.py +++ b/setup.py @@ -114,6 +114,7 @@ def _extract_tarball(self, tarball_path, lib_dir): license='BSD 2-Clause', ext_modules = [jq_extension], cmdclass={"build_ext": jq_build_ext}, + package_data={"jq": ["py.typed"]}, classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', @@ -129,4 +130,3 @@ def _extract_tarball(self, tarball_path, lib_dir): 'Programming Language :: Python :: 3.12', ], ) - From 8de4cc8194532ae9f86bea0e072e944e31b89812 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Sun, 30 Jun 2024 12:19:32 +0200 Subject: [PATCH 2/2] Simplify stubs --- jq.pyi | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) diff --git a/jq.pyi b/jq.pyi index 9f71d17..d1de0f1 100644 --- a/jq.pyi +++ b/jq.pyi @@ -1,7 +1,7 @@ from collections.abc import Iterable -from typing import Any, Literal, overload +from typing import Any, overload -from typing_extensions import Self, TypeAlias, deprecated +from typing_extensions import Self, TypeAlias JSON: TypeAlias = Any @@ -9,9 +9,6 @@ class _EmptyValue: ... _NO_VALUE: _EmptyValue -class _JqStatePool: - def __init__(self, program_bytes: bytes, args: Any) -> None: ... - class _Program: def __init__(self, program_bytes: bytes, args: Any) -> None: ... @overload @@ -24,45 +21,14 @@ class _Program: @property def program_string(self) -> str: ... def __repr__(self) -> str: ... - @overload - @deprecated("'transform' is kept for 0.1.x backwards compatibility") - def transform( - self, - value: JSON | _EmptyValue = _NO_VALUE, - text: JSON | _EmptyValue = _NO_VALUE, - *, - text_output: Literal[True], - multiple_output: Literal[False] = False, - ) -> str: ... - @overload - @deprecated("'transform' is kept for 0.1.x backwards compatibility") - def transform( - self, - value: JSON | _EmptyValue = _NO_VALUE, - text: JSON | _EmptyValue = _NO_VALUE, - *, - text_output: Literal[False] = False, - multiple_output: Literal[True], - ) -> list[JSON]: ... - @overload - @deprecated("'transform' is kept for 0.1.x backwards compatibility") - def transform( - self, - value: JSON | _EmptyValue = _NO_VALUE, - text: JSON | _EmptyValue = _NO_VALUE, - text_output: Literal[False] = False, - multiple_output: Literal[False] = False, - ) -> JSON: ... class _ProgramWithInput: - def __init__(self, jq_state_pool: _JqStatePool, bytes_input: bytes, *, slurp: bool) -> None: ... def __iter__(self) -> _ResultIterator: ... def text(self) -> str: ... def all(self) -> list[JSON]: ... def first(self) -> JSON: ... class _ResultIterator: - def __init__(self, jq_state_pool: _JqStatePool, bytes_input: bytes, *, slurp: bool) -> None: ... def __iter__(self) -> Self: ... def __next__(self) -> JSON: ... @@ -83,5 +49,3 @@ def iter(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> _ResultI def text(program: str, value: JSON, text: _EmptyValue = _NO_VALUE) -> str: ... @overload def text(program: str, value: _EmptyValue = _NO_VALUE, *, text: str) -> str: ... -@deprecated("'jq' is kept for 0.1.x backwards compatibility") -def jq(program: str) -> _Program: ...