Fix documentation & coding style of User.name & User.full_name (#956)

- Use string `format` instead of dict comprehension.
 - Better documentation to signify the semantics difference between
   `name` and `full_name`.

 - Use string `format` instead of dict comprehension.
 - Better documentation to signify the semantics difference between
   `name` and `full_name`.

* Removed the NOTE and mentinoed the "@" prefix.
This commit is contained in:
Noam Meltzer 2017-12-30 22:58:32 +02:00 committed by GitHub
parent 0faa19726a
commit a2c04313d3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -72,26 +72,23 @@ class User(TelegramObject):
@property
def name(self):
"""
:obj:`str`: The users :attr:`username` if available, if not it returns the first name and
if present :attr:`first_name` and :attr:`last_name`.
:obj:`str`: Convenience property. If available, returns the user's :attr:`username`
prefixed with "@". If :attr:`username` is not available, returns :attr:`full_name`.
"""
if self.username:
return '@%s' % self.username
if self.last_name:
return '%s %s' % (self.first_name, self.last_name)
return self.first_name
return '@{}'.format(self.username)
return self.full_name
@property
def full_name(self):
"""
:obj:`str`: The users :attr:`first_name` and if present :attr:`last_name`.
:obj:`str`: Convenience property. The user's :attr:`first_name`, followed by (if available)
:attr:`last_name`.
"""
if self.last_name:
return '%s %s' % (self.first_name, self.last_name)
return '{} {}'.format(self.first_name, self.last_name)
return self.first_name
@classmethod