88"""Parse SQL statements."""
99
1010# Setup namespace
11+ from typing import Any , Generator , IO , List , Optional , Tuple , Union
12+
1113from sqlparse import sql
1214from sqlparse import cli
1315from sqlparse import engine
1618from sqlparse import formatter
1719
1820
19- __version__ = ' 0.5.4.dev0'
20- __all__ = [' engine' , ' filters' , ' formatter' , ' sql' , ' tokens' , ' cli' ]
21+ __version__ = " 0.5.4.dev0"
22+ __all__ = [" engine" , " filters" , " formatter" , " sql" , " tokens" , " cli" ]
2123
2224
23- def parse (sql , encoding = None ):
25+ def parse (
26+ sql : str , encoding : Optional [str ] = None
27+ ) -> Tuple [sql .Statement , ...]:
2428 """Parse sql and return a list of statements.
2529
2630 :param sql: A string containing one or more SQL statements.
@@ -30,7 +34,9 @@ def parse(sql, encoding=None):
3034 return tuple (parsestream (sql , encoding ))
3135
3236
33- def parsestream (stream , encoding = None ):
37+ def parsestream (
38+ stream : Union [str , IO [str ]], encoding : Optional [str ] = None
39+ ) -> Generator [sql .Statement , None , None ]:
3440 """Parses sql statements from file-like object.
3541
3642 :param stream: A file-like object.
@@ -42,7 +48,7 @@ def parsestream(stream, encoding=None):
4248 return stack .run (stream , encoding )
4349
4450
45- def format (sql , encoding = None , ** options ) :
51+ def format (sql : str , encoding : Optional [ str ] = None , ** options : Any ) -> str :
4652 """Format *sql* according to *options*.
4753
4854 Available options are documented in :ref:`formatting`.
@@ -56,10 +62,12 @@ def format(sql, encoding=None, **options):
5662 options = formatter .validate_options (options )
5763 stack = formatter .build_filter_stack (stack , options )
5864 stack .postprocess .append (filters .SerializerUnicode ())
59- return '' .join (stack .run (sql , encoding ))
65+ return "" .join (stack .run (sql , encoding ))
6066
6167
62- def split (sql , encoding = None , strip_semicolon = False ):
68+ def split (
69+ sql : str , encoding : Optional [str ] = None , strip_semicolon : bool = False
70+ ) -> List [str ]:
6371 """Split *sql* into single statements.
6472
6573 :param sql: A string containing one or more SQL statements.
0 commit comments