Browse Source

Type-Hint appinfo/team

pull/7043/head
Josh 4 years ago
committed by GitHub
parent
commit
04788d0a06
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 70
      discord/appinfo.py
  2. 26
      discord/team.py
  3. 4
      discord/types/team.py

70
discord/appinfo.py

@ -24,15 +24,19 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from typing import TYPE_CHECKING, Optional
from typing import List, TYPE_CHECKING, Optional
from . import utils
from .asset import Asset
if TYPE_CHECKING:
from .guild import Guild
from .types.appinfo import AppInfo as AppInfoPayload, PartialAppInfo as PartialAppInfoPayload
from .types.appinfo import (
AppInfo as AppInfoPayload,
PartialAppInfo as PartialAppInfoPayload,
Team as TeamPayload,
)
from .user import User
from .state import ConnectionState
__all__ = (
@ -131,32 +135,32 @@ class AppInfo:
'privacy_policy_url',
)
def __init__(self, state, data: AppInfoPayload):
def __init__(self, state: ConnectionState, data: AppInfoPayload):
from .team import Team
self._state = state
self.id = int(data['id'])
self.name = data['name']
self.description = data['description']
self._icon = data['icon']
self.rpc_origins = data['rpc_origins']
self.bot_public = data['bot_public']
self.bot_require_code_grant = data['bot_require_code_grant']
self.owner = state.store_user(data['owner'])
self._state: ConnectionState = state
self.id: int = int(data['id'])
self.name: str = data['name']
self.description: str = data['description']
self._icon: Optional[str] = data['icon']
self.rpc_origins: List[str] = data['rpc_origins']
self.bot_public: bool = data['bot_public']
self.bot_require_code_grant: bool = data['bot_require_code_grant']
self.owner: User = state.store_user(data['owner'])
team = data.get('team')
self.team = Team(state, team) if team else None
team: Optional[TeamPayload] = data.get('team')
self.team: Optional[Team] = Team(state, team) if team else None
self.summary = data['summary']
self.verify_key = data['verify_key']
self.summary: str = data['summary']
self.verify_key: str = data['verify_key']
self.guild_id = utils._get_as_snowflake(data, 'guild_id')
self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
self.primary_sku_id = utils._get_as_snowflake(data, 'primary_sku_id')
self.slug = data.get('slug')
self._cover_image = data.get('cover_image')
self.terms_of_service_url = data.get('terms_of_service_url')
self.privacy_policy_url = data.get('privacy_policy_url')
self.primary_sku_id: Optional[int] = utils._get_as_snowflake(data, 'primary_sku_id')
self.slug: Optional[str] = data.get('slug')
self._cover_image: Optional[str] = data.get('cover_image')
self.terms_of_service_url: Optional[str] = data.get('terms_of_service_url')
self.privacy_policy_url: Optional[str] = data.get('privacy_policy_url')
def __repr__(self) -> str:
return (
@ -221,16 +225,16 @@ class PartialAppInfo:
__slots__ = ('_state', 'id', 'name', 'description', 'rpc_origins', 'summary', 'verify_key', 'terms_of_service_url', 'privacy_policy_url', '_icon')
def __init__(self, *, state: ConnectionState, data: PartialAppInfoPayload):
self._state = state
self.id = int(data['id'])
self.name = data['name']
self._icon = data.get('icon')
self.description = data['description']
self.rpc_origins = data.get('rpc_origins')
self.summary = data['summary']
self.verify_key = data['verify_key']
self.terms_of_service_url = data.get('terms_of_service_url')
self.privacy_policy_url = data.get('privacy_policy_url')
self._state: ConnectionState = state
self.id: int = int(data['id'])
self.name: str = data['name']
self._icon: Optional[str] = data.get('icon')
self.description: str = data['description']
self.rpc_origins: Optional[List[str]] = data.get('rpc_origins')
self.summary: str = data['summary']
self.verify_key: str = data['verify_key']
self.terms_of_service_url: Optional[str] = data.get('terms_of_service_url')
self.privacy_policy_url: Optional[str] = data.get('privacy_policy_url')
def __repr__(self) -> str:
return f'<{self.__class__.__name__} id={self.id} name={self.name!r} description={self.description!r}>'

26
discord/team.py

@ -29,9 +29,11 @@ from .user import BaseUser
from .asset import Asset
from .enums import TeamMembershipState, try_enum
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING, Optional, List
if TYPE_CHECKING:
from .state import ConnectionState
from .types.team import (
Team as TeamPayload,
TeamMember as TeamMemberPayload,
@ -62,14 +64,14 @@ class Team:
__slots__ = ('_state', 'id', 'name', '_icon', 'owner_id', 'members')
def __init__(self, state, data: TeamPayload):
self._state = state
def __init__(self, state: ConnectionState, data: TeamPayload):
self._state: ConnectionState = state
self.id = int(data['id'])
self.name = data['name']
self._icon = data['icon']
self.owner_id = utils._get_as_snowflake(data, 'owner_user_id')
self.members = [TeamMember(self, self._state, member) for member in data['members']]
self.id: int = int(data['id'])
self.name: str = data['name']
self._icon: Optional[str] = data['icon']
self.owner_id: Optional[int] = utils._get_as_snowflake(data, 'owner_user_id')
self.members: List[TeamMember] = [TeamMember(self, self._state, member) for member in data['members']]
def __repr__(self) -> str:
return f'<{self.__class__.__name__} id={self.id} name={self.name}>'
@ -130,10 +132,10 @@ class TeamMember(BaseUser):
__slots__ = BaseUser.__slots__ + ('team', 'membership_state', 'permissions')
def __init__(self, team: Team, state, data: TeamMemberPayload):
self.team = team
self.membership_state = try_enum(TeamMembershipState, data['membership_state'])
self.permissions = data['permissions']
def __init__(self, team: Team, state: ConnectionState, data: TeamMemberPayload):
self.team: Team = team
self.membership_state: TeamMembershipState = try_enum(TeamMembershipState, data['membership_state'])
self.permissions: List[str] = data['permissions']
super().__init__(state=state, data=data['user'])
def __repr__(self) -> str:

4
discord/types/team.py

@ -24,7 +24,7 @@ DEALINGS IN THE SOFTWARE.
from __future__ import annotations
from typing import TypedDict, List
from typing import TypedDict, List, Optional
from .user import PartialUser
from .snowflake import Snowflake
@ -40,4 +40,4 @@ class Team(TypedDict):
name: str
owner_id: Snowflake
members: List[TeamMember]
icon: str
icon: Optional[str]

Loading…
Cancel
Save