Skip to content
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

Clarify behavior of Token.match method #796

Open
wants to merge 1 commit 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
18 changes: 9 additions & 9 deletions sqlparse/sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,14 @@ def flatten(self):
def match(self, ttype, values, regex=False):
"""Checks whether the token matches the given arguments.

*ttype* is a token type. If this token doesn't match the given token
type.
*values* is a list of possible values for this token. The values
are OR'ed together so if only one of the values matches ``True``
is returned. Except for keyword tokens the comparison is
case-sensitive. For convenience it's OK to pass in a single string.
If *regex* is ``True`` (default is ``False``) the given values are
treated as regular expressions.
*ttype* is a token type as defined in `sqlparse.tokens`. If it does
not match, ``False`` is returned.
*values* is a list of possible values for this token. For match to be
considered valid, the token value needs to be in this list. For tokens
of type ``Keyword`` the comparison is case-insensitive. For
convenience, a single value can be given passed as a string.
If *regex* is ``True``, the given values are treated as regular
expressions. Partial matches are allowed. Defaults to ``False``.
"""
type_matched = self.ttype is ttype
if not type_matched or values is None:
Expand All @@ -107,7 +107,7 @@ def match(self, ttype, values, regex=False):
values = (values,)

if regex:
# TODO: Add test for regex with is_keyboard = false
# TODO: Add test for regex with is_keyword = false
flag = re.IGNORECASE if self.is_keyword else 0
values = (re.compile(v, flag) for v in values)

Expand Down