Skip to content

Raise exception when match failure, to distinguish from “matched, value is None” #113

@benf-wspdigital

Description

@benf-wspdigital

The jmespath.search function returns None in two distinct cases:

>>> import jmespath

>>> foo = {'bar': {'lorem': 13, 'ipsum': None}}
>>> repr(jmespath.search('bar.lorem', foo))
'13'
>>> repr(jmespath.search('bar.ipsum', foo))    # Path matches, value None
'None'
>>> repr(jmespath.search('dolor', foo))    # Path does not match
'None'

It appears the JMESPath search API returns None in these two distinct cases. How can the caller know the difference between them?

I would expect no return in the case of a match failure, and instead an exception (such as KeyError or ValueError).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions