Skip to content

Commit 2de0395

Browse files
committed
.format -> f-strings
1 parent 7cef136 commit 2de0395

3 files changed

Lines changed: 15 additions & 19 deletions

File tree

dbl/errors.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ def __init__(self, response, message):
6262
else:
6363
self.text = message
6464

65-
fmt = '{0.reason} (status code: {0.status})'
65+
fmt = f"{self.response.reason} (status code: {self.response.status})"
6666
if self.text:
67-
fmt = fmt + ': {1}'
67+
fmt = f"{fmt}: {self.text}"
6868

69-
super().__init__(fmt.format(self.response, self.text))
69+
super().__init__(fmt)
7070

7171

7272
class Unauthorized(HTTPException):

dbl/http.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333

3434
import aiohttp
3535
from aiohttp import ClientResponse
36-
from .ratelimiter import AsyncRateLimiter
3736

3837
from . import __version__, errors
38+
from .ratelimiter import AsyncRateLimiter
3939

4040
log = logging.getLogger(__name__)
4141

@@ -85,15 +85,12 @@ def __init__(self, token, **kwargs):
8585
self._global_over = asyncio.Event()
8686
self._global_over.set()
8787

88-
user_agent = 'topggpy (https://github.com/top-gg/python-sdk {0}) Python/{1[0]}.{1[' \
89-
'1]} aiohttp/{2}'
90-
self.user_agent = user_agent.format(__version__, sys.version_info, aiohttp.__version__)
91-
92-
# NOTE: current implementation doesn't maintain state over restart
88+
self.user_agent = f"topggpy (https://github.com/top-gg/python-sdk {__version__}) Python/" \
89+
f"{sys.version_info[0]}.{sys.version_info[1]} aiohttp/{aiohttp.__version__}"
9390

9491
async def request(self, method, url, **kwargs) -> Union[dict, str]:
9592
"""Handles requests to the API."""
96-
url = "{0}{1}".format(self.BASE, url)
93+
url = f"{self.BASE}{url}"
9794

9895
# handles rate limits.
9996
# max_calls is set to 59 because current implementation will retry in 60s
@@ -182,11 +179,11 @@ async def get_weekend_status(self):
182179

183180
async def get_guild_count(self, bot_id):
184181
"""Gets the guild count of the given Bot ID."""
185-
return await self.request('GET', '/bots/{}/stats'.format(bot_id))
182+
return await self.request('GET', f'/bots/{bot_id}/stats')
186183

187184
async def get_bot_info(self, bot_id):
188185
"""Gets the information of a bot under given bot ID on top.gg."""
189-
resp: Union[dict, str] = await self.request('GET', '/bots/{}'.format(bot_id))
186+
resp: Union[dict, str] = await self.request('GET', f'/bots/{bot_id}')
190187
resp['date'] = datetime.strptime(resp['date'], '%Y-%m-%dT%H:%M:%S.%fZ')
191188
for k in resp:
192189
if resp[k] == '':
@@ -195,26 +192,26 @@ async def get_bot_info(self, bot_id):
195192

196193
async def get_bot_upvotes(self, bot_id):
197194
"""Gets your bot's last 1000 votes on top.gg."""
198-
return await self.request('GET', '/bots/{}/votes'.format(bot_id))
195+
return await self.request('GET', f'/bots/{bot_id}/votes')
199196

200197
async def get_bots(self, limit, offset, sort, search, fields):
201198
"""Gets an object of bots on top.gg."""
202199
if limit > 500:
203200
limit = 50
204201
fields = ', '.join(fields)
205-
search = ' '.join(['{}: {}'.format(field, value) for field, value in search.items()])
202+
search = ' '.join([f'{field}: {value}' for field, value in search.items()])
206203

207204
return await self.request('GET', '/bots', params={
208205
'limit': limit, 'offset': offset, 'sort': sort, 'search': search, 'fields': fields
209206
})
210207

211208
async def get_user_info(self, user_id):
212209
"""Gets an object of the user on top.gg."""
213-
return await self.request('GET', '/users/{}'.format(user_id))
210+
return await self.request('GET', f'/users/{user_id}')
214211

215212
async def get_user_vote(self, bot_id, user_id):
216213
"""Gets info whether the user has upvoted your bot."""
217-
return await self.request('GET', '/bots/{}/check'.format(bot_id), params={'userId': user_id})
214+
return await self.request('GET', f'/bots/{bot_id}/check', params={'userId': user_id})
218215

219216

220217
async def _ratelimit_handler(until):

setup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
readme = f.read()
2323

2424
setup(name='dblpy',
25-
author='{author}, top.gg'.format(author=author),
25+
author=f'{author}, top.gg',
2626
author_email='shivaco.osu@gmail.com',
2727
url='https://github.com/top-gg/python-sdk',
2828
version=version,
@@ -33,15 +33,14 @@
3333
include_package_data=True,
3434
python_requires='>= 3.5.3',
3535
install_requires=requirements,
36-
keywords='discord bot list discordbots botlist topgg top.gg',
36+
keywords='discord bot server list discordservers serverlist discordbots botlist topgg top.gg',
3737
classifiers=[
3838
'Development Status :: 5 - Production/Stable',
3939
'License :: OSI Approved :: MIT License',
4040
'Intended Audience :: Developers',
4141
'Natural Language :: English',
4242
'Operating System :: OS Independent',
4343
'Programming Language :: Python :: 3 :: Only',
44-
'Programming Language :: Python :: 3.5',
4544
'Programming Language :: Python :: 3.6',
4645
'Programming Language :: Python :: 3.7',
4746
'Programming Language :: Python :: 3.8',

0 commit comments

Comments
 (0)