@@ -422,17 +422,20 @@ def get_real_name(self):
422422 return self ._get_first_name (self .token_index (dot ))
423423
424424 return self ._get_first_name ()
425+
426+ def get_parent_name (self ):
427+ """Return name of the parent object if any.
428+
429+ A parent object is identified by the first occuring dot.
430+ """
431+ dot = self .token_next_match (0 , T .Punctuation , '.' )
425432 if dot is None :
426- next_ = self .token_next_by_type (0 , T .Name )
427- if next_ is not None :
428- return self ._remove_quotes (next_ .value )
429433 return None
430-
431- next_ = self .token_next_by_type (self .token_index (dot ),
432- (T .Name , T .Wildcard , T .String .Symbol ))
433- if next_ is None : # invalid identifier, e.g. "a."
434+ prev_ = self .token_prev (self .token_index (dot ))
435+ if prev_ is None : # something must be verry wrong here..
434436 return None
435- return self ._remove_quotes (next_ .value )
437+ return self ._remove_quotes (prev_ .value )
438+
436439 def _get_first_name (self , idx = None , reverse = False , keywords = False ):
437440 """Returns the name of the first token with a name"""
438441
@@ -485,19 +488,6 @@ class Identifier(TokenList):
485488
486489 __slots__ = ('value' , 'ttype' , 'tokens' )
487490
488- def get_parent_name (self ):
489- """Return name of the parent object if any.
490-
491- A parent object is identified by the first occuring dot.
492- """
493- dot = self .token_next_match (0 , T .Punctuation , '.' )
494- if dot is None :
495- return None
496- prev_ = self .token_prev (self .token_index (dot ))
497- if prev_ is None : # something must be verry wrong here..
498- return None
499- return self ._remove_quotes (prev_ .value )
500-
501491 def is_wildcard (self ):
502492 """Return ``True`` if this identifier contains a wildcard."""
503493 token = self .token_next_by_type (0 , T .Wildcard )
0 commit comments