Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
andialbrecht committed Apr 3, 2016
1 parent 03594bb commit ee5799f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
12 changes: 5 additions & 7 deletions sqlparse/__init__.py
Expand Up @@ -10,11 +10,11 @@


# Setup namespace
from sqlparse import engine
from sqlparse import filters
from sqlparse import formatter
from sqlparse import engine # noqa
from sqlparse import filters # noqa
from sqlparse import formatter # noqa

from sqlparse.compat import u
from sqlparse.compat import u # noqa


def parse(sql, encoding=None):
Expand Down Expand Up @@ -69,9 +69,7 @@ def split(sql, encoding=None):
return [u(stmt).strip() for stmt in stack.run(sql, encoding)]


from sqlparse.engine.filter import StatementFilter


def split2(stream):
from sqlparse.engine.filter import StatementFilter
splitter = StatementFilter()
return list(splitter.process(None, stream))
43 changes: 19 additions & 24 deletions sqlparse/engine/grouping.py
Expand Up @@ -5,11 +5,6 @@
from sqlparse import sql
from sqlparse import tokens as T

try:
next
except NameError: # Python < 2.6
next = lambda i: i.next()


def _group_left_right(tlist, ttype, value, cls,
check_right=lambda t: True,
Expand Down Expand Up @@ -441,23 +436,23 @@ def align_comments(tlist):

def group(tlist):
for func in [
group_comments,
group_brackets,
group_functions,
group_where,
group_case,
group_identifier,
group_order,
group_typecasts,
group_as,
group_aliased,
group_assignment,
group_comparison,
align_comments,
group_identifier_list,
group_if,
group_for,
group_foreach,
group_begin,
]:
group_comments,
group_brackets,
group_functions,
group_where,
group_case,
group_identifier,
group_order,
group_typecasts,
group_as,
group_aliased,
group_assignment,
group_comparison,
align_comments,
group_identifier_list,
group_if,
group_for,
group_foreach,
group_begin,
]:
func(tlist)
6 changes: 4 additions & 2 deletions sqlparse/sql.py
Expand Up @@ -491,9 +491,11 @@ def get_type(self):
# The WITH keyword should be followed by either an Identifier or
# an IdentifierList containing the CTE definitions; the actual
# DML keyword (e.g. SELECT, INSERT) will follow next.
idents = self.token_next(self.token_index(first_token), skip_ws=True)
idents = self.token_next(
self.token_index(first_token), skip_ws=True)
if isinstance(idents, (Identifier, IdentifierList)):
dml_keyword = self.token_next(self.token_index(idents), skip_ws=True)
dml_keyword = self.token_next(
self.token_index(idents), skip_ws=True)
if dml_keyword.ttype == T.Keyword.DML:
return dml_keyword.normalized
# Hmm, probably invalid syntax, so return unknown.
Expand Down
5 changes: 4 additions & 1 deletion tox.ini
Expand Up @@ -12,4 +12,7 @@ commands=
[testenv:flake8]
basepython=python3.5
deps=flake8
commands=flake8 --exclude=docs/ .
commands=flake8 sqlparse

[flake8]
ignore = W503

0 comments on commit ee5799f

Please sign in to comment.