Skip to content

Commit 2307dfc

Browse files
committed
Ignore .tox when linting, better docstrings
1 parent 2c52782 commit 2307dfc

6 files changed

Lines changed: 141 additions & 127 deletions

File tree

brawlstats/core.py

Lines changed: 84 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import requests
99
from cachetools import TTLCache
1010

11+
from typing import Union
12+
1113
from .errors import Forbidden, NotFoundError, RateLimitError, ServerError, UnexpectedError
1214
from .models import BattleLog, Brawlers, Club, Constants, Members, Player, Ranking
1315
from .utils import API, bstag, typecasted
@@ -16,30 +18,28 @@
1618

1719

1820
class Client:
19-
"""
20-
This is a sync/async client class that lets you access the Brawl Stars API
21+
"""A sync/async client class that lets you access the Brawl Stars API
2122
2223
Parameters
2324
------------
2425
token: str
2526
The API Key that you can get from https://developer.brawlstars.com
26-
timeout: Optional[int] = 30
27-
How long to wait in seconds before shutting down requests.
28-
is_async: Optional[bool] = False
29-
Setting this to ``True`` makes the client async. Default is ``False``
30-
session: Optional[Union[requests.Session, aiohttp.ClientSession]] = None
31-
Use a current session or a make new one.
32-
loop: Optional[asyncio.window_events._WindowsSelectorEventLoop]
33-
The event loop to use for asynchronous operations. Defaults to ``None``,
34-
in which case the default event loop is ``asyncio.get_event_loop()``.
35-
connector: Optional[aiohttp.TCPConnector]
36-
Pass a TCPConnector into the client (aiohttp). Defaults to ``None``.
37-
debug: Optional[bool] = False
38-
Whether or not to log info for debugging.
39-
prevent_ratelimit: Optional[bool] = False
40-
Whether or not to wait between requests to prevent being ratelimited.
41-
base_url: Optional[str] = None
42-
Sets a different base URL to make request to.
27+
session: Union[requests.Session, aiohttp.ClientSession], optional
28+
Use a current session or a make new one, by default None
29+
timeout: int, optional
30+
How long to wait in seconds before shutting down requests, by default 30
31+
is_async: bool, optional
32+
Setting this to ``True`` makes the client async, by default False
33+
loop: asyncio.window_events._WindowsSelectorEventLoop, optional
34+
The event loop to use for asynchronous operations, by default None
35+
connector: aiohttp.TCPConnector, optional
36+
Pass a TCPConnector into the client (aiohttp), by default None
37+
debug: bool, optional
38+
Whether or not to log info for debugging, by default False
39+
prevent_ratelimit: bool, optional
40+
Whether or not to wait between requests to prevent being ratelimited, by default False
41+
base_url: str, optional
42+
Sets a different base URL to make request to, by default None
4343
"""
4444

4545
REQUEST_LOG = '{method} {url} recieved {text} has returned {status}'
@@ -202,88 +202,106 @@ def _get_model(self, url, model, key=None):
202202
return model(self, data)
203203

204204
@typecasted
205-
def get_player(self, tag: bstag):
206-
"""
207-
Get a player's stats.
205+
def get_player(self, tag: bstag) -> Player:
206+
"""Gets a player's stats.
208207
209208
Parameters
210209
----------
211-
tag: str
210+
tag : str
212211
A valid player tag.
213212
Valid characters: 0289PYLQGRJCUV
214213
215-
Returns Player
214+
Returns
215+
-------
216+
Player
217+
A player object with all of its attributes.
216218
"""
217219
url = '{}/{}'.format(self.api.PROFILE, tag)
218220
return self._get_model(url, model=Player)
219221

220222
get_profile = get_player
221223

222224
@typecasted
223-
def get_battle_logs(self, tag: bstag):
224-
"""Get a player's battle logs.
225+
def get_battle_logs(self, tag: bstag) -> BattleLog:
226+
"""Gets a player's battle logs.
225227
226228
Parameters
227229
----------
228-
tag: str
230+
tag : str
229231
A valid player tag.
230232
Valid characters: 0289PYLQGRJCUV
231233
232-
Returns BattleLog
234+
Returns
235+
-------
236+
BattleLog
237+
A player battle object with all of its attributes.
233238
"""
234239
url = '{}/{}/battlelog'.format(self.api.PROFILE, tag)
235240
return self._get_model(url, model=BattleLog)
236241

237242
@typecasted
238-
def get_club(self, tag: bstag):
239-
"""
240-
Get a club's stats.
243+
def get_club(self, tag: bstag) -> Club:
244+
"""Gets a club's stats.
241245
242246
Parameters
243247
----------
244-
tag: str
248+
tag : str
245249
A valid club tag.
246250
Valid characters: 0289PYLQGRJCUV
247251
248-
Returns Club
252+
Returns
253+
-------
254+
Club
255+
A club object with all of its attributes.
249256
"""
250257
url = '{}/{}'.format(self.api.CLUB, tag)
251258
return self._get_model(url, model=Club)
252259

253260
@typecasted
254-
def get_club_members(self, tag: bstag):
255-
"""
256-
Get the members of a club.
261+
def get_club_members(self, tag: bstag) -> Members:
262+
"""Gets the members of a club.
257263
258264
Parameters
259265
----------
260-
tag: str
266+
tag : str
261267
A valid club tag.
262268
Valid characters: 0289PYLQGRJCUV
263269
264-
Returns Members
270+
Returns
271+
-------
272+
Members
273+
A list of the members in a club.
265274
"""
266275
url = '{}/{}/members'.format(self.api.CLUB, tag)
267276
return self._get_model(url, model=Members)
268277

269-
def get_rankings(self, *, ranking: str, region=None, limit: int=200, brawler=None):
270-
"""
271-
Get the top count players/clubs/brawlers.
278+
def get_rankings(self, *, ranking: str, region: str=None, limit: int=200, brawler: Union[str, int]=None) -> Ranking:
279+
"""Gets the top count players/clubs/brawlers.
272280
273281
Parameters
274282
----------
275-
ranking: str
283+
ranking : str
276284
The type of ranking. Must be "players", "clubs", "brawlers".
277-
Anything else will return a ValueError.
278-
region: Optional[str]
279-
The region to retrieve from. Must be a 2 letter country code.
280-
limit: Optional[int] = 200
281-
The number of top players or clubs to fetch.
282-
If count > 200, it will return a ValueError.
283-
brawler: Optional[Union[str, int]] = None
284-
The brawler name or ID.
285-
286-
Returns Ranking
285+
region : str, optional
286+
The region to retrieve from. Must be a 2 letter country code, by default None
287+
limit : int, optional
288+
The number of top players or clubs to fetch, by default 200
289+
brawler : Union[str, int], optional
290+
The brawler name or ID, by default None
291+
292+
Returns
293+
-------
294+
Ranking
295+
A player or club ranking that contains a list of players or clubs.
296+
297+
Raises
298+
------
299+
ValueError
300+
The brawler name or ID is invalid.
301+
ValueError
302+
`rankings` is not "players", "clubs", or "brawlers"
303+
ValueError
304+
`limit` is not between 1 and 200, inclusive.
287305
"""
288306
if brawler is not None:
289307
if isinstance(brawler, str):
@@ -312,25 +330,27 @@ def get_rankings(self, *, ranking: str, region=None, limit: int=200, brawler=Non
312330

313331
return self._get_model(url, model=Ranking)
314332

315-
def get_constants(self, key=None):
316-
"""
317-
Gets Brawl Stars constants extracted from the app.
333+
def get_constants(self, key: str=None) -> Constants:
334+
"""Gets Brawl Stars constants extracted from the app.
318335
319336
Parameters
320337
----------
321-
key: Optional[str] = None
322-
Any key to get specific data.
338+
key : str, optional
339+
Any key to get specific data, by default None
323340
324-
Returns Constants
341+
Returns
342+
-------
343+
Constants
344+
Data containing some Brawl Stars constants.
325345
"""
326346
return self._get_model(self.api.CONSTANTS, model=Constants, key=key)
327347

328-
def get_brawlers(self):
329-
"""
330-
Get available brawlers and information about them.
331-
332-
No parameters
348+
def get_brawlers(self) -> Brawlers:
349+
"""Gets available brawlers and information about them.
333350
334-
Returns Brawlers
351+
Returns
352+
-------
353+
Brawlers
354+
A list of available brawlers and information about them.
335355
"""
336356
return self._get_model(self.api.BRAWLERS, model=Brawlers)

brawlstats/errors.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def __init__(self, code, **kwargs):
3535

3636
class RateLimitError(RequestError):
3737
"""Raised when the rate limit is reached."""
38+
3839
def __init__(self, code, url):
3940
self.code = code
4041
self.url = url

brawlstats/models.py

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from box import Box, BoxList
2-
from .utils import bstag
32

3+
from .utils import bstag
44

55
__all__ = ['Player', 'Club', 'Members', 'Ranking', 'BattleLog', 'Constants', 'Brawlers']
66

@@ -41,70 +41,66 @@ def __len__(self):
4141
return sum(1 for i in self)
4242

4343

44-
class Player(BaseBox):
45-
"""
46-
Returns a full player object with all of its attributes.
47-
"""
44+
class Members(BaseBoxList):
45+
"""A list of the members in a club."""
4846

49-
def __init__(self, *args, **kwargs):
50-
super().__init__(*args, **kwargs)
51-
self.team_victories = self.x3vs3_victories
47+
def __init__(self, client, data):
48+
super().__init__(client, data['items'])
5249

5350
def __repr__(self):
54-
return "<Player object name='{0.name}' tag='{0.tag}'>".format(self)
55-
56-
def __str__(self):
57-
return '{0.name} ({0.tag})'.format(self)
58-
59-
def get_club(self):
60-
"""
61-
Gets the player's club.
62-
63-
Returns Optional[Club]
64-
"""
65-
if not self.club:
66-
return None
67-
url = '{}/{}'.format(self.client.api.CLUB, bstag(self.club.tag))
68-
return self.client._get_model(url, model=Club)
51+
return '<Members object count={}>'.format(len(self))
6952

7053

7154
class Club(BaseBox):
72-
"""
73-
Returns a full club object with all of its attributes.
74-
"""
55+
"""A club object with all of its attributes."""
7556

7657
def __repr__(self):
7758
return "<Club object name='{0.name}' tag='{0.tag}'>".format(self)
7859

7960
def __str__(self):
8061
return '{0.name} ({0.tag})'.format(self)
8162

82-
def get_members(self):
83-
"""
84-
Gets the members of a club.
63+
def get_members(self) -> Members:
64+
"""Gets the members of a club.
8565
86-
Returns Members
66+
Returns
67+
-------
68+
Members
69+
A list of the members in a club.
8770
"""
8871
url = '{}/{}/members'.format(self.client.api.CLUB, bstag(self.tag))
8972
return self.client._get_model(url, model=Members)
9073

9174

92-
class Members(BaseBoxList):
93-
"""
94-
Returns the members in a club.
95-
"""
75+
class Player(BaseBox):
76+
"""A player object with all of its attributes."""
9677

97-
def __init__(self, client, data):
98-
super().__init__(client, data['items'])
78+
def __init__(self, *args, **kwargs):
79+
super().__init__(*args, **kwargs)
80+
self.team_victories = self.x3vs3_victories
9981

10082
def __repr__(self):
101-
return '<Members object count={}>'.format(len(self))
83+
return "<Player object name='{0.name}' tag='{0.tag}'>".format(self)
84+
85+
def __str__(self):
86+
return '{0.name} ({0.tag})'.format(self)
87+
88+
def get_club(self) -> Club:
89+
"""Gets the player's club.
90+
91+
Returns
92+
-------
93+
Club or None
94+
A list of the members in a club, or None if the player is not in a club.
95+
"""
96+
if not self.club:
97+
return None
98+
url = '{}/{}'.format(self.client.api.CLUB, bstag(self.club.tag))
99+
return self.client._get_model(url, model=Club)
102100

103101

104102
class Ranking(BaseBoxList):
105-
"""
106-
Returns a player or club ranking that contains a list of players or clubs.
107-
"""
103+
"""A player or club ranking that contains a list of players or clubs."""
108104

109105
def __init__(self, client, data):
110106
super().__init__(client, data['items'])
@@ -114,25 +110,19 @@ def __repr__(self):
114110

115111

116112
class BattleLog(BaseBoxList):
117-
"""
118-
Returns a full player battle object with all of its attributes.
119-
"""
113+
"""A player battle object with all of its attributes."""
120114

121115
def __init__(self, client, data):
122116
super().__init__(client, data['items'])
123117

124118

125119
class Constants(BaseBox):
126-
"""
127-
Returns some Brawl Stars constants.
128-
"""
120+
"""Data containing some Brawl Stars constants."""
129121
pass
130122

131123

132124
class Brawlers(BaseBoxList):
133-
"""
134-
Returns list of available brawlers and information about them.
135-
"""
125+
"""A list of available brawlers and information about them."""
136126

137127
def __init__(self, client, data):
138128
super().__init__(client, data['items'])

0 commit comments

Comments
 (0)