def get_parent_name(self): """Return name of the parent object if any. A parent object is identified by the first occurring dot. """ dot_idx, _ = self.token_next_by(m=(T.Punctuation, ".")) _, prev_ = self.token_prev(dot_idx) return remove_quotes(prev_.value) if prev_ is not None else None
def get_parent_name(self): """Return name of the parent object if any. A parent object is identified by the first occuring dot. """ dot = self.token_next_by(m=(T.Punctuation, '.')) prev_ = self.token_prev(dot) return remove_quotes(prev_.value) if prev_ is not None else None
def get_parent_name(self): """Return name of the parent object if any. A parent object is identified by the first occuring dot. """ dot = self.token_next_match(0, T.Punctuation, '.') if dot is None: return None prev_ = self.token_prev(self.token_index(dot)) if prev_ is None: # something must be verry wrong here.. return None return remove_quotes(prev_.value)
def _get_first_name(self, idx=None): """Returns the name of the first token with a name""" tokens = self.tokens[idx:] if idx else self.tokens types = [T.Name, T.Wildcard, T.String.Symbol, T.Alias] for token in tokens: if token.ttype in types: return remove_quotes(token.value) # this is probably a result of nesting identifiers. elif isinstance(token, (Identifier, Function)): return token.get_name()
def _get_first_name(self, idx=None, reverse=False, keywords=False): """Returns the name of the first token with a name""" tokens = self.tokens[idx:] if idx else self.tokens tokens = reversed(tokens) if reverse else tokens types = [T.Name, T.Wildcard, T.String.Symbol] if keywords: types.append(T.Keyword) for token in tokens: if token.ttype in types: return remove_quotes(token.value) elif isinstance(token, (Identifier, Function)): return token.get_name()
def _get_first_name(self, idx=None, reverse=False, keywords=False): """Returns the name of the first token with a name""" if idx and not isinstance(idx, int): idx = self.token_index(idx) + 1 tokens = self.tokens[idx:] if idx else self.tokens tokens = reversed(tokens) if reverse else tokens types = [T.Name, T.Wildcard, T.String.Symbol] if keywords: types.append(T.Keyword) for tok in tokens: if tok.ttype in types: return remove_quotes(tok.value) elif isinstance(tok, Identifier) or isinstance(tok, Function): return tok.get_name() return None
def get_alias(self): """Returns the alias for this identifier or ``None``.""" _, alias = self.token_next_by(t=T.Alias) return remove_quotes(alias.value) if alias is not None else None