Skip to content

Commit a2c0431

Browse files
authored
Fix documentation & coding style of User.name & User.full_name (python-telegram-bot#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.
1 parent 0faa197 commit a2c0431

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

telegram/user.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,26 +72,23 @@ def __init__(self,
7272
@property
7373
def name(self):
7474
"""
75-
:obj:`str`: The users :attr:`username` if available, if not it returns the first name and
76-
if present :attr:`first_name` and :attr:`last_name`.
75+
:obj:`str`: Convenience property. If available, returns the user's :attr:`username`
76+
prefixed with "@". If :attr:`username` is not available, returns :attr:`full_name`.
7777
7878
"""
79-
8079
if self.username:
81-
return '@%s' % self.username
82-
if self.last_name:
83-
return '%s %s' % (self.first_name, self.last_name)
84-
return self.first_name
80+
return '@{}'.format(self.username)
81+
return self.full_name
8582

8683
@property
8784
def full_name(self):
8885
"""
89-
:obj:`str`: The users :attr:`first_name` and if present :attr:`last_name`.
86+
:obj:`str`: Convenience property. The user's :attr:`first_name`, followed by (if available)
87+
:attr:`last_name`.
9088
9189
"""
92-
9390
if self.last_name:
94-
return '%s %s' % (self.first_name, self.last_name)
91+
return '{} {}'.format(self.first_name, self.last_name)
9592
return self.first_name
9693

9794
@classmethod

0 commit comments

Comments
 (0)