Skip to content

Commit 370152b

Browse files
committed
Simplify sql.py naming/alias
1 parent 4ef134f commit 370152b

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

sqlparse/sql.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -373,41 +373,29 @@ def get_alias(self):
373373
if len(self.tokens) > 2 and self.token_next_by(t=T.Whitespace):
374374
return self._get_first_name(reverse=True)
375375

376-
return None
377-
378376
def get_name(self):
379377
"""Returns the name of this identifier.
380378
381379
This is either it's alias or it's real name. The returned valued can
382380
be considered as the name under which the object corresponding to
383381
this identifier is known within the current statement.
384382
"""
385-
alias = self.get_alias()
386-
if alias is not None:
387-
return alias
388-
return self.get_real_name()
383+
return self.get_alias() or self.get_real_name()
389384

390385
def get_real_name(self):
391386
"""Returns the real name (object name) of this identifier."""
392387
# a.b
393-
dot = self.token_next_match(0, T.Punctuation, '.')
394-
if dot is not None:
395-
return self._get_first_name(self.token_index(dot))
396-
397-
return self._get_first_name()
388+
dot = self.token_next_by(m=(T.Punctuation, '.'))
389+
return self._get_first_name(dot)
398390

399391
def get_parent_name(self):
400392
"""Return name of the parent object if any.
401393
402394
A parent object is identified by the first occuring dot.
403395
"""
404-
dot = self.token_next_match(0, T.Punctuation, '.')
405-
if dot is None:
406-
return None
407-
prev_ = self.token_prev(self.token_index(dot))
408-
if prev_ is None: # something must be verry wrong here..
409-
return None
410-
return remove_quotes(prev_.value)
396+
dot = self.token_next_by(m=(T.Punctuation, '.'))
397+
prev_ = self.token_prev(dot)
398+
return remove_quotes(prev_.value) if prev_ is not None else None
411399

412400
def _get_first_name(self, idx=None, reverse=False, keywords=False):
413401
"""Returns the name of the first token with a name"""
@@ -427,7 +415,6 @@ def _get_first_name(self, idx=None, reverse=False, keywords=False):
427415
return remove_quotes(tok.value)
428416
elif isinstance(tok, Identifier) or isinstance(tok, Function):
429417
return tok.get_name()
430-
return None
431418

432419

433420
class Statement(TokenList):

0 commit comments

Comments
 (0)