Skip to content

QueryList: Use operator, add doctest #371

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions libvcs/_internal/query_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
----
This is an internal API not covered by versioning policy.
"""
import operator
import re
import traceback
from typing import Any, Callable, Optional, Protocol, Sequence, TypeVar, Union
Expand Down Expand Up @@ -53,12 +54,19 @@ def parse_lookup(obj, path, lookup):
class LookupProtocol(Protocol):
"""Protocol for :class:`QueryList` filtering operators."""

def __call__(self, data: Union[list[str], str], rhs: Union[list[str], str]):
def __call__(self, data: Any, rhs: Any):
"""Callback for :class:`QueryList` filtering operators."""


def lookup_exact(data, rhs):
return rhs == data
lookup_exact = operator.eq
"""Exact match. Alias of :func:`operator.eq`.

>>> lookup_exact("cat", "cat")
True

>>> lookup_exact("cat", "dog")
False
"""


def lookup_iexact(data, rhs):
Expand Down