Qualify attribute names for generated ivar (#5129)

* Use qualified name in ivar

* bugfix

* fix style

* Moves _qualify_name into class to be more consistent with surrounding code
This commit is contained in:
Toshiki Kataoka 2018-09-23 22:25:31 +09:00 committed by Rob Ruana
parent 329c3f457e
commit bd1e33643c

View File

@ -608,6 +608,7 @@ class GoogleDocstring(UnicodeMixin):
lines = []
for _name, _type, _desc in self._consume_fields():
if self._config.napoleon_use_ivar:
_name = self._qualify_name(_name, self._obj)
field = ':ivar %s: ' % _name # type: unicode
lines.extend(self._format_block(field, _desc))
if _type:
@ -784,6 +785,18 @@ class GoogleDocstring(UnicodeMixin):
colon,
"".join(after_colon).strip())
def _qualify_name(self, attr_name, klass):
# type: (unicode, type) -> unicode
if klass and '.' not in attr_name:
if attr_name.startswith('~'):
attr_name = attr_name[1:]
try:
q = klass.__qualname__
except AttributeError:
q = klass.__name__
return '~%s.%s' % (q, attr_name)
return attr_name
def _strip_empty(self, lines):
# type: (List[unicode]) -> List[unicode]
if lines: