From 6a6a677ae3ef618b956d82cf08cd48dbae462a5b Mon Sep 17 00:00:00 2001 From: Avasam Date: Thu, 5 Jan 2023 06:37:08 -0500 Subject: [PATCH] Improve various `jmespath` types Merge `jmespath` from microsoft/python-type-stubs --- stubs/jmespath/jmespath/exceptions.pyi | 47 +++++++++++++------------- stubs/jmespath/jmespath/functions.pyi | 5 +-- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/stubs/jmespath/jmespath/exceptions.pyi b/stubs/jmespath/jmespath/exceptions.pyi index 8bbb095c2..e09d9425a 100644 --- a/stubs/jmespath/jmespath/exceptions.pyi +++ b/stubs/jmespath/jmespath/exceptions.pyi @@ -1,44 +1,43 @@ +from collections.abc import Sequence from typing import Any class JMESPathError(ValueError): ... class ParseError(JMESPathError): - lex_position: Any - token_value: Any - token_type: Any - msg: Any - expression: Any - def __init__(self, lex_position, token_value, token_type, msg=...) -> None: ... + lex_position: int + token_value: str + token_type: str + msg: str + expression: str | None + def __init__(self, lex_position: int, token_value: str, token_type: str, msg: str = ...) -> None: ... class IncompleteExpressionError(ParseError): - expression: Any - lex_position: Any - token_type: Any - token_value: Any - def set_expression(self, expression) -> None: ... + # When ParseError is used directly, the token always have a non-null value and type + token_value: str | None # type: ignore[assignment] + token_type: str | None # type: ignore[assignment] + expression: str + def set_expression(self, expression: str) -> None: ... class LexerError(ParseError): - lexer_position: Any - lexer_value: Any - message: Any - expression: Any - def __init__(self, lexer_position, lexer_value, message, expression: Any | None = ...) -> None: ... + lexer_position: int + lexer_value: str + message: str + def __init__(self, lexer_position: int, lexer_value: str, message: str, expression: str | None = ...) -> None: ... class ArityError(ParseError): - expected_arity: Any - actual_arity: Any - function_name: Any - expression: Any + expected_arity: int + actual_arity: int + function_name: str def __init__(self, expected, actual, name) -> None: ... class VariadictArityError(ArityError): ... class JMESPathTypeError(JMESPathError): - function_name: Any + function_name: str current_value: Any - actual_type: Any - expected_types: Any - def __init__(self, function_name, current_value, actual_type, expected_types) -> None: ... + actual_type: str + expected_types: Sequence[str] + def __init__(self, function_name: str, current_value: Any, actual_type: str, expected_types: Sequence[str]) -> None: ... class EmptyExpressionError(JMESPathError): def __init__(self) -> None: ... diff --git a/stubs/jmespath/jmespath/functions.pyi b/stubs/jmespath/jmespath/functions.pyi index 64bb19d55..836f80e38 100644 --- a/stubs/jmespath/jmespath/functions.pyi +++ b/stubs/jmespath/jmespath/functions.pyi @@ -1,4 +1,4 @@ -from collections.abc import Callable +from collections.abc import Callable, Iterable from typing import Any, TypeVar from typing_extensions import NotRequired, TypedDict @@ -18,4 +18,5 @@ class FunctionRegistry(type): class Functions(metaclass=FunctionRegistry): FUNCTION_TABLE: Any - def call_function(self, function_name, resolved_args): ... + # resolved_args and return value are the *args and return of a function called by name + def call_function(self, function_name: str, resolved_args: Iterable[Any]) -> Any: ...