Skip to content

Commit 6314de7

Browse files
committed
Remove OverrideDoc and just copy-paste them for now. Add doc to cached property members.
1 parent c61226d commit 6314de7

File tree

7 files changed

+63
-43
lines changed

7 files changed

+63
-43
lines changed

coc/abc.py

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -30,47 +30,7 @@
3030
from .players import Player
3131

3232

33-
class OverrideDoc(type):
34-
"""Helper metaclass to make Sphinx recognise attributes from base classes.
35-
36-
This just overrides the object's docstring and injects any documented attributes from the base classes.
37-
"""
38-
39-
def __new__(cls, *args, **kwargs):
40-
_, bases, _ = args
41-
new_cls = super().__new__(cls, *args, **kwargs)
42-
43-
for obj in bases:
44-
if obj.__doc__ is None:
45-
continue
46-
if new_cls.__doc__ is None:
47-
continue
48-
if "Attributes" not in obj.__doc__:
49-
continue
50-
51-
try:
52-
doc = obj.__doc__.split("Attributes")[1].split("\n\n")[0]
53-
except (KeyError, AttributeError):
54-
continue
55-
56-
if "Attributes" not in new_cls.__doc__:
57-
new_cls.__doc__ += "\nAttributes\n----------\n" + doc.replace("----------", "")
58-
else:
59-
try:
60-
insert = new_cls.__doc__.index("Attributes")
61-
except ValueError:
62-
return new_cls
63-
64-
# fmt: off
65-
new_cls.__doc__ = (
66-
new_cls.__doc__[:insert + 25] + doc.replace("----------", "") + new_cls.__doc__[insert + 25:]
67-
)
68-
# fmt: on
69-
70-
return new_cls
71-
72-
73-
class BaseClan(metaclass=OverrideDoc):
33+
class BaseClan:
7434
"""An ABC that implements some common operations on clans, regardless of type.
7535
7636
Attributes
@@ -142,7 +102,7 @@ def get_detailed_members(self, cls: Type["Player"] = None) -> AsyncIterator["Pla
142102
return PlayerIterator(self._client, (p.tag for p in self.members), cls=cls)
143103

144104

145-
class BasePlayer(metaclass=OverrideDoc):
105+
class BasePlayer:
146106
"""An ABC that implements some common operations on players, regardless of type.
147107
148108
Attributes

coc/clans.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ class RankedClan(BaseClan):
3535
3636
Attributes
3737
----------
38+
tag: :class:`str`
39+
The clan's tag
40+
name: :class:`str`
41+
The clan's name
42+
badge: :class:`Badge`
43+
The clan's badge
44+
level: :class:`int`
45+
The clan's level.
3846
location: :class:`Location`
3947
The clan's location.
4048
member_count: :class:`int`
@@ -78,6 +86,14 @@ class Clan(BaseClan):
7886
7987
Attributes
8088
----------
89+
tag: :class:`str`
90+
The clan's tag
91+
name: :class:`str`
92+
The clan's name
93+
badge: :class:`Badge`
94+
The clan's badge
95+
level: :class:`int`
96+
The clan's level.
8197
type: :class:`str`
8298
The clan's type for accepting members.
8399
This could be ``open``, ``inviteOnly`` or ``closed``.

coc/player_clan.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,15 @@
2727

2828
class PlayerClan(BaseClan):
2929
"""Represents a clan that belongs to a player.
30+
31+
Attributes
32+
----------
33+
tag: :class:`str`
34+
The clan's tag
35+
name: :class:`str`
36+
The clan's name
37+
badge: :class:`Badge`
38+
The clan's badge
39+
level: :class:`int`
40+
The clan's level.
3041
"""

coc/players.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class ClanMember(BasePlayer):
5252
5353
Attributes
5454
----------
55+
tag: :class:`str`
56+
The player's tag
57+
name: :class:`str`
58+
The player's name
5559
clan: Optional[:class:`Clan`]
5660
The player's clan. If the player is clanless, this will be ``None``.
5761
role: :class:`Role`

coc/utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class _CachedProperty(Generic[T, T_co]):
328328
def __init__(self, name: str, function: Callable[[T], T_co]) -> None:
329329
self.name = name
330330
self.function = function
331+
self.__doc__ = getattr(function, '__doc__')
331332

332333
def __get__(self, instance: T, owner: Type[T]) -> T_co:
333334
try:

coc/war_clans.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ class WarClan(BaseClan):
4848
4949
Attributes
5050
----------
51+
tag: :class:`str`
52+
The clan's tag
53+
name: :class:`str`
54+
The clan's name
55+
badge: :class:`Badge`
56+
The clan's badge
57+
level: :class:`int`
58+
The clan's level.
5159
stars:
5260
:class:`int`: Number of stars by clan this war.
5361
destruction:
@@ -157,7 +165,19 @@ def get_member(self, tag: str) -> typing.Optional[ClanWarMember]:
157165

158166

159167
class ClanWarLeagueClan(BaseClan):
160-
"""Represents a Clan War League Clan."""
168+
"""Represents a Clan War League Clan.
169+
170+
Attributes
171+
----------
172+
tag: :class:`str`
173+
The clan's tag
174+
name: :class:`str`
175+
The clan's name
176+
badge: :class:`Badge`
177+
The clan's badge
178+
level: :class:`int`
179+
The clan's level.
180+
"""
161181

162182
__slots__ = BaseClan.__slots__ + ("_cs_members", "_iter_members")
163183

coc/war_members.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ class ClanWarMember(BasePlayer):
3838
3939
Attributes
4040
----------
41+
tag: :class:`str`
42+
The player's tag
43+
name: :class:`str`
44+
The player's name
4145
town_hall:
4246
:class:`int`: The member's townhall level.
4347
map_position:
@@ -138,6 +142,10 @@ class ClanWarLeagueClanMember(BasePlayer):
138142
139143
Attributes
140144
----------
145+
tag: :class:`str`
146+
The player's tag
147+
name: :class:`str`
148+
The player's name
141149
town_hall: :class:`int`
142150
The player's town hall level.
143151
"""

0 commit comments

Comments
 (0)