Skip to content
This repository has been archived by the owner on Dec 26, 2022. It is now read-only.

Commit

Permalink
Merge pull request #272 from Sigmanificient/http
Browse files Browse the repository at this point in the history
  • Loading branch information
Arthurdw authored Dec 1, 2021
2 parents 00d24e0 + 09a2a42 commit 26847c0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pincer/objects/guild/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async def from_id(cls, client: Client, _id: Union[int, Snowflake]) -> Guild:
channel_data = await client.http.get(f"/guilds/{_id}/channels")

data["channels"]: List[Channel] = [
Channel.from_dict({**i, "_client": client, "_http": client.http})
Channel.from_dict(construct_client_dict(client, i))
for i in (channel_data or [])
]

Expand Down
7 changes: 4 additions & 3 deletions pincer/objects/guild/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from ..user.user import User
from ...utils.api_object import APIObject
from ...utils.conversion import construct_client_dict
from ...utils.snowflake import Snowflake
from ...utils.timestamp import Timestamp
from ...utils.types import MISSING
Expand Down Expand Up @@ -134,7 +135,7 @@ async def from_id(
cls,
client: Client,
guild_id: int,
_id: int
user_id: int
) -> GuildMember:
data = await client.http.get(f"guilds/{guild_id}/members/{_id}")
return cls.from_dict({**data, "_client": client, "_http": client.http})
data = await client.http.get(f"guilds/{guild_id}/members/{user_id}")
return cls.from_dict(construct_client_dict(client, data))
2 changes: 1 addition & 1 deletion pincer/utils/api_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class APIObject(metaclass=HTTPMeta):
Represents an object which has been fetched from the Discord API.
"""
_client: Client
_http: HTTPClient

def __get_types(self, attr: str, arg_type: type) -> Tuple[type]:
"""Get the types from type annotations.
Expand Down Expand Up @@ -173,6 +172,7 @@ def __attr_convert(self, attr_value: Dict, attr_type: T) -> T:
)

def __post_init__(self):
self._http = getattr(self._client, "http", None)
TypeCache()

# Get all type annotations for the attributes.
Expand Down
2 changes: 1 addition & 1 deletion pincer/utils/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def construct_client_dict(client: Client, data: Dict) -> Dict:
-------
"""
return {**data, "_client": client, "_http": client.http}
return {**data, "_client": client}


def convert(
Expand Down

0 comments on commit 26847c0

Please sign in to comment.