jmespath / jmespath.py

JMESPath is a query language for JSON.
http://jmespath.org
MIT License
2.19k stars 181 forks source link

False positive with mypy #305

Open Franco0700 opened 1 year ago

Franco0700 commented 1 year ago

Defining a customFunctions, like this:

class CustomFunctions(jmespath.functions.Functions):
        @jmespath.functions.signature({'types': ['object']}, {'types': ['array']})
        def _func_map_merge(self, obj: str, arg: list[dict[str, str]]) -> list[dict[str, str]]:
            result = []
            for element in arg:
                merged_object = super()._func_merge(obj, element)
                result.append(merged_object)
            return result

Drop the following error

error: "_func_merge" undefined in superclass

I think it should be some missing information on stubs

jamesls commented 1 year ago

I'm not able to repro, can you give me the entire script as well as the commands you're running? Here's what I tried:

import jmespath
from jmespath import functions
from typing import List, Dict

class CustomFunctions(functions.Functions):
    @functions.signature({'types': ['object']}, {'types': ['array']})
    def _func_map_merge(self, obj: str, arg: List[Dict[str, str]]) -> List[Dict[str, str]]:
        result = []
        for element in arg:
            merged_object = super()._func_merge(obj, element)
            result.append(merged_object)
        return result

options = jmespath.Options(custom_functions=CustomFunctions())
$ mypy check.py
Success: no issues found in 1 source file