diff options
author | Amjith Ramanujam <amjith.r@gmail.com> | 2018-11-18 20:11:15 -0800 |
---|---|---|
committer | Irina Truong <i.chernyavska@gmail.com> | 2018-11-18 20:11:15 -0800 |
commit | 25a66ecfb3dee049b4094d5113bbd178dc190bef (patch) | |
tree | e40b44a4c9f6a0f76041fe776b42af8d0ad535cf | |
parent | 923f2d64417ed8ab3b778b87a517e64c0534b6ec (diff) |
Fix the StopIteration issue in Python 3.7 (#971)
* Fix the StopIteration issue in Python 3.7
-rw-r--r-- | changelog.rst | 1 | ||||
-rw-r--r-- | pgcli/packages/parseutils/tables.py | 54 |
2 files changed, 29 insertions, 26 deletions
diff --git a/changelog.rst b/changelog.rst index d4ff20d8..087546d5 100644 --- a/changelog.rst +++ b/changelog.rst @@ -8,6 +8,7 @@ Bug fixes: * Set default port in `connect_uri` when none is given. (Thanks: `Daniel Egger`_) * Fix for error listing databases (#951). (Thanks: `Irina Truong`_) * Enable Ctrl-Z to suspend the app (Thanks: `Amjith Ramanujam`_). +* Fix StopIteration exception raised at runtime for Python 3.7 (Thanks: `Amjith Ramanujam`_). Internal: --------- diff --git a/pgcli/packages/parseutils/tables.py b/pgcli/packages/parseutils/tables.py index dc80a2ce..607b5009 100644 --- a/pgcli/packages/parseutils/tables.py +++ b/pgcli/packages/parseutils/tables.py @@ -36,11 +36,11 @@ def extract_from_part(parsed, stop_at_punctuation=True): for x in extract_from_part(item, stop_at_punctuation): yield x elif stop_at_punctuation and item.ttype is Punctuation: - raise StopIteration + return # An incomplete nested select won't be recognized correctly as a # sub-select. eg: 'SELECT * FROM (SELECT id FROM user'. This causes # the second FROM to trigger this elif condition resulting in a - # StopIteration. So we need to ignore the keyword if the keyword + # `return`. So we need to ignore the keyword if the keyword # FROM. # Also 'SELECT * FROM abc JOIN def' will trigger this elif # condition. So we need to ignore the keyword JOIN and its variants @@ -93,30 +93,32 @@ def extract_table_identifiers(token_stream, allow_functions=True): name = name.lower() return schema_name, name, alias - - for item in token_stream: - if isinstance(item, IdentifierList): - for identifier in item.get_identifiers(): - # Sometimes Keywords (such as FROM ) are classified as - # identifiers which don't have the get_real_name() method. - try: - schema_name = identifier.get_parent_name() - real_name = identifier.get_real_name() - is_function = (allow_functions and - _identifier_is_function(identifier)) - except AttributeError: - continue - if real_name: - yield TableReference(schema_name, real_name, - identifier.get_alias(), is_function) - elif isinstance(item, Identifier): - schema_name, real_name, alias = parse_identifier(item) - is_function = allow_functions and _identifier_is_function(item) - - yield TableReference(schema_name, real_name, alias, is_function) - elif isinstance(item, Function): - schema_name, real_name, alias = parse_identifier(item) - yield TableReference(None, real_name, alias, allow_functions) + try: + for item in token_stream: + if isinstance(item, IdentifierList): + for identifier in item.get_identifiers(): + # Sometimes Keywords (such as FROM ) are classified as + # identifiers which don't have the get_real_name() method. + try: + schema_name = identifier.get_parent_name() + real_name = identifier.get_real_name() + is_function = (allow_functions and + _identifier_is_function(identifier)) + except AttributeError: + continue + if real_name: + yield TableReference(schema_name, real_name, + identifier.get_alias(), is_function) + elif isinstance(item, Identifier): + schema_name, real_name, alias = parse_identifier(item) + is_function = allow_functions and _identifier_is_function(item) + + yield TableReference(schema_name, real_name, alias, is_function) + elif isinstance(item, Function): + schema_name, real_name, alias = parse_identifier(item) + yield TableReference(None, real_name, alias, allow_functions) + except StopIteration: + return # extract_tables is inspired from examples in the sqlparse lib. |