Skip to content

Commit aa702f6

Browse files
committed
Improve import logic & __future__ annotations
1 parent a8d903c commit aa702f6

21 files changed

+56
-149
lines changed

discord/types/activity.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@
2525

2626
from __future__ import annotations
2727

28-
import sys
2928
from typing import Literal
3029

30+
from .._typed_dict import NotRequired, TypedDict
3131
from .snowflake import Snowflake
3232
from .user import PartialUser
3333

34-
if sys.version_info >= (3, 11):
35-
from typing import NotRequired, TypedDict
36-
else:
37-
from typing_extensions import NotRequired, TypedDict
38-
39-
4034
StatusType = Literal["idle", "dnd", "online", "offline"]
4135

4236

discord/types/appinfo.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,11 @@
2525

2626
from __future__ import annotations
2727

28-
import sys
29-
28+
from .._typed_dict import NotRequired, TypedDict
3029
from .snowflake import Snowflake
3130
from .team import Team
3231
from .user import User
3332

34-
if sys.version_info >= (3, 11):
35-
from typing import NotRequired, TypedDict
36-
else:
37-
from typing_extensions import NotRequired, TypedDict
38-
3933

4034
class BaseAppInfo(TypedDict):
4135
id: Snowflake

discord/types/audit_log.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525

2626
from __future__ import annotations
2727

28-
import sys
2928
from typing import Literal, Union
3029

30+
from .._typed_dict import NotRequired, TypedDict
3131
from .automod import AutoModRule
3232
from .channel import ChannelType, PermissionOverwrite, VideoQualityMode
3333
from .guild import (
@@ -44,12 +44,6 @@
4444
from .user import User
4545
from .webhook import Webhook
4646

47-
if sys.version_info >= (3, 11):
48-
from typing import NotRequired, TypedDict
49-
else:
50-
from typing_extensions import NotRequired, TypedDict
51-
52-
5347
AuditLogEvent = Literal[
5448
1,
5549
10,

discord/types/automod.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,11 @@
2222

2323
from __future__ import annotations
2424

25-
import sys
2625
from typing import Literal
2726

27+
from .._typed_dict import NotRequired, TypedDict
2828
from .snowflake import Snowflake
2929

30-
if sys.version_info >= (3, 11):
31-
from typing import NotRequired, TypedDict
32-
else:
33-
from typing_extensions import NotRequired, TypedDict
34-
35-
3630
AutoModTriggerType = Literal[1, 2, 3, 4]
3731

3832
AutoModEventType = Literal[1]

discord/types/channel.py

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,15 @@
2222
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2323
DEALINGS IN THE SOFTWARE.
2424
"""
25-
import sys
26-
from typing import List, Literal, Optional, Union
25+
from __future__ import annotations
2726

27+
from typing import Literal, Union
28+
29+
from .._typed_dict import NotRequired, TypedDict
2830
from .snowflake import Snowflake
2931
from .threads import ThreadArchiveDuration, ThreadMember, ThreadMetadata
3032
from .user import PartialUser
3133

32-
if sys.version_info >= (3, 11):
33-
from typing import NotRequired, TypedDict
34-
else:
35-
from typing_extensions import NotRequired, TypedDict
36-
37-
3834
OverwriteType = Literal[0, 1]
3935

4036

@@ -56,9 +52,9 @@ class _BaseChannel(TypedDict):
5652
class _BaseGuildChannel(_BaseChannel):
5753
guild_id: Snowflake
5854
position: int
59-
permission_overwrites: List[PermissionOverwrite]
55+
permission_overwrites: list[PermissionOverwrite]
6056
nsfw: bool
61-
parent_id: Optional[Snowflake]
57+
parent_id: Snowflake | None
6258

6359

6460
class PartialChannel(_BaseChannel):
@@ -67,7 +63,7 @@ class PartialChannel(_BaseChannel):
6763

6864
class _TextChannelOptional(TypedDict, total=False):
6965
topic: str
70-
last_message_id: Optional[Snowflake]
66+
last_message_id: Snowflake | None
7167
last_pin_timestamp: str
7268
rate_limit_per_user: int
7369
default_auto_archive_duration: ThreadArchiveDuration
@@ -89,7 +85,7 @@ class NewsChannel(_BaseGuildChannel, _TextChannelOptional):
8985

9086

9187
class VoiceChannel(_BaseGuildChannel):
92-
rtc_region: NotRequired[Optional[str]]
88+
rtc_region: NotRequired[str | None]
9389
video_quality_mode: NotRequired[VideoQualityMode]
9490
type: Literal[2]
9591
bitrate: int
@@ -101,7 +97,7 @@ class CategoryChannel(_BaseGuildChannel):
10197

10298

10399
class StageChannel(_BaseGuildChannel):
104-
rtc_region: NotRequired[Optional[str]]
100+
rtc_region: NotRequired[str | None]
105101
topic: NotRequired[str]
106102
type: Literal[13]
107103
bitrate: int
@@ -112,7 +108,7 @@ class ThreadChannel(_BaseChannel):
112108
member: NotRequired[ThreadMember]
113109
owner_id: NotRequired[Snowflake]
114110
rate_limit_per_user: NotRequired[int]
115-
last_message_id: NotRequired[Optional[Snowflake]]
111+
last_message_id: NotRequired[Snowflake | None]
116112
last_pin_timestamp: NotRequired[str]
117113
type: Literal[10, 11, 12]
118114
guild_id: Snowflake
@@ -137,13 +133,13 @@ class ThreadChannel(_BaseChannel):
137133
class DMChannel(TypedDict):
138134
id: Snowflake
139135
type: Literal[1]
140-
last_message_id: Optional[Snowflake]
141-
recipients: List[PartialUser]
136+
last_message_id: Snowflake | None
137+
recipients: list[PartialUser]
142138

143139

144140
class GroupDMChannel(_BaseChannel):
145141
type: Literal[3]
146-
icon: Optional[str]
142+
icon: str | None
147143
owner_id: Snowflake
148144

149145

discord/types/components.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,11 @@
2525

2626
from __future__ import annotations
2727

28-
import sys
2928
from typing import Literal, Union
3029

30+
from .._typed_dict import NotRequired, TypedDict
3131
from .emoji import PartialEmoji
3232

33-
if sys.version_info >= (3, 11):
34-
from typing import NotRequired, TypedDict
35-
else:
36-
from typing_extensions import NotRequired, TypedDict
37-
3833
ComponentType = Literal[1, 2, 3, 4]
3934
ButtonStyle = Literal[1, 2, 3, 4, 5]
4035
InputTextStyle = Literal[1, 2]

discord/types/embed.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2323
DEALINGS IN THE SOFTWARE.
2424
"""
25-
import sys
26-
from typing import List, Literal
25+
from __future__ import annotations
2726

28-
if sys.version_info >= (3, 11):
29-
from typing import NotRequired, TypedDict
30-
else:
31-
from typing_extensions import NotRequired, TypedDict
27+
from typing import Literal
28+
29+
from .._typed_dict import NotRequired, TypedDict
3230

3331

3432
class EmbedFooter(TypedDict):
@@ -94,4 +92,4 @@ class Embed(TypedDict, total=False):
9492
video: EmbedVideo
9593
provider: EmbedProvider
9694
author: EmbedAuthor
97-
fields: List[EmbedField]
95+
fields: list[EmbedField]

discord/types/emoji.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,17 @@
2222
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2323
DEALINGS IN THE SOFTWARE.
2424
"""
25+
from __future__ import annotations
2526

26-
from typing import Optional, TypedDict
27+
from typing import TypedDict
2728

2829
from .snowflake import Snowflake, SnowflakeList
2930
from .user import User
3031

3132

3233
class PartialEmoji(TypedDict):
33-
id: Optional[Snowflake]
34-
name: Optional[str]
34+
id: Snowflake | None
35+
name: str | None
3536

3637

3738
class Emoji(PartialEmoji, total=False):
@@ -45,4 +46,4 @@ class Emoji(PartialEmoji, total=False):
4546

4647
class EditEmoji(TypedDict):
4748
name: str
48-
roles: Optional[SnowflakeList]
49+
roles: SnowflakeList | None

discord/types/guild.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
"""
2525
from __future__ import annotations
2626

27-
import sys
2827
from typing import Literal
2928

29+
from .._typed_dict import NotRequired, Required, TypedDict
3030
from .activity import PartialPresenceUpdate
3131
from .channel import GuildChannel
3232
from .emoji import Emoji
@@ -39,11 +39,6 @@
3939
from .voice import GuildVoiceState
4040
from .welcome_screen import WelcomeScreen
4141

42-
if sys.version_info >= (3, 11):
43-
from typing import NotRequired, Required, TypedDict
44-
else:
45-
from typing_extensions import NotRequired, Required, TypedDict
46-
4742

4843
class Ban(TypedDict):
4944
reason: str | None

discord/types/integration.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,12 @@
2525

2626
from __future__ import annotations
2727

28-
import sys
2928
from typing import Literal, Union
3029

30+
from .._typed_dict import NotRequired, TypedDict
3131
from .snowflake import Snowflake
3232
from .user import User
3333

34-
if sys.version_info >= (3, 11):
35-
from typing import NotRequired, TypedDict
36-
else:
37-
from typing_extensions import NotRequired, TypedDict
38-
3934

4035
class IntegrationApplication(TypedDict):
4136
bot: NotRequired[User]

0 commit comments

Comments
 (0)