Skip to content

Commit 59e1c5e

Browse files
committed
Run pyupgrade
1 parent 5e445b3 commit 59e1c5e

File tree

2 files changed

+49
-57
lines changed

2 files changed

+49
-57
lines changed

discord/colour.py

Lines changed: 38 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@
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

2627
import colorsys
2728
import random
28-
from typing import Any, Optional, Tuple, Type, TypeVar, Union
29+
from typing import Any, TypeVar
2930

3031
__all__ = (
3132
"Colour",
@@ -115,31 +116,31 @@ def b(self) -> int:
115116
""":class:`int`: Returns the blue component of the colour."""
116117
return self._get_byte(0)
117118

118-
def to_rgb(self) -> Tuple[int, int, int]:
119+
def to_rgb(self) -> tuple[int, int, int]:
119120
"""Tuple[:class:`int`, :class:`int`, :class:`int`]: Returns an (r, g, b) tuple representing the colour."""
120121
return self.r, self.g, self.b
121122

122123
@classmethod
123-
def from_rgb(cls: Type[CT], r: int, g: int, b: int) -> CT:
124+
def from_rgb(cls: type[CT], r: int, g: int, b: int) -> CT:
124125
"""Constructs a :class:`Colour` from an RGB tuple."""
125126
return cls((r << 16) + (g << 8) + b)
126127

127128
@classmethod
128-
def from_hsv(cls: Type[CT], h: float, s: float, v: float) -> CT:
129+
def from_hsv(cls: type[CT], h: float, s: float, v: float) -> CT:
129130
"""Constructs a :class:`Colour` from an HSV tuple."""
130131
rgb = colorsys.hsv_to_rgb(h, s, v)
131132
return cls.from_rgb(*(int(x * 255) for x in rgb))
132133

133134
@classmethod
134-
def default(cls: Type[CT]) -> CT:
135+
def default(cls: type[CT]) -> CT:
135136
"""A factory method that returns a :class:`Colour` with a value of ``0``."""
136137
return cls(0)
137138

138139
@classmethod
139140
def random(
140-
cls: Type[CT],
141+
cls: type[CT],
141142
*,
142-
seed: Optional[Union[int, str, float, bytes, bytearray]] = None,
143+
seed: int | str | float | bytes | bytearray | None = None,
143144
) -> CT:
144145
"""A factory method that returns a :class:`Colour` with a random hue.
145146
@@ -161,146 +162,146 @@ def random(
161162
return cls.from_hsv(rand.random(), 1, 1)
162163

163164
@classmethod
164-
def teal(cls: Type[CT]) -> CT:
165+
def teal(cls: type[CT]) -> CT:
165166
"""A factory method that returns a :class:`Colour` with a value of ``0x1abc9c``."""
166167
return cls(0x1ABC9C)
167168

168169
@classmethod
169-
def dark_teal(cls: Type[CT]) -> CT:
170+
def dark_teal(cls: type[CT]) -> CT:
170171
"""A factory method that returns a :class:`Colour` with a value of ``0x11806a``."""
171172
return cls(0x11806A)
172173

173174
@classmethod
174-
def brand_green(cls: Type[CT]) -> CT:
175+
def brand_green(cls: type[CT]) -> CT:
175176
"""A factory method that returns a :class:`Colour` with a value of ``0x57F287``.
176177
177178
.. versionadded:: 2.0
178179
"""
179180
return cls(0x57F287)
180181

181182
@classmethod
182-
def green(cls: Type[CT]) -> CT:
183+
def green(cls: type[CT]) -> CT:
183184
"""A factory method that returns a :class:`Colour` with a value of ``0x2ecc71``."""
184185
return cls(0x2ECC71)
185186

186187
@classmethod
187-
def dark_green(cls: Type[CT]) -> CT:
188+
def dark_green(cls: type[CT]) -> CT:
188189
"""A factory method that returns a :class:`Colour` with a value of ``0x1f8b4c``."""
189190
return cls(0x1F8B4C)
190191

191192
@classmethod
192-
def blue(cls: Type[CT]) -> CT:
193+
def blue(cls: type[CT]) -> CT:
193194
"""A factory method that returns a :class:`Colour` with a value of ``0x3498db``."""
194195
return cls(0x3498DB)
195196

196197
@classmethod
197-
def dark_blue(cls: Type[CT]) -> CT:
198+
def dark_blue(cls: type[CT]) -> CT:
198199
"""A factory method that returns a :class:`Colour` with a value of ``0x206694``."""
199200
return cls(0x206694)
200201

201202
@classmethod
202-
def purple(cls: Type[CT]) -> CT:
203+
def purple(cls: type[CT]) -> CT:
203204
"""A factory method that returns a :class:`Colour` with a value of ``0x9b59b6``."""
204205
return cls(0x9B59B6)
205206

206207
@classmethod
207-
def dark_purple(cls: Type[CT]) -> CT:
208+
def dark_purple(cls: type[CT]) -> CT:
208209
"""A factory method that returns a :class:`Colour` with a value of ``0x71368a``."""
209210
return cls(0x71368A)
210211

211212
@classmethod
212-
def magenta(cls: Type[CT]) -> CT:
213+
def magenta(cls: type[CT]) -> CT:
213214
"""A factory method that returns a :class:`Colour` with a value of ``0xe91e63``."""
214215
return cls(0xE91E63)
215216

216217
@classmethod
217-
def dark_magenta(cls: Type[CT]) -> CT:
218+
def dark_magenta(cls: type[CT]) -> CT:
218219
"""A factory method that returns a :class:`Colour` with a value of ``0xad1457``."""
219220
return cls(0xAD1457)
220221

221222
@classmethod
222-
def gold(cls: Type[CT]) -> CT:
223+
def gold(cls: type[CT]) -> CT:
223224
"""A factory method that returns a :class:`Colour` with a value of ``0xf1c40f``."""
224225
return cls(0xF1C40F)
225226

226227
@classmethod
227-
def dark_gold(cls: Type[CT]) -> CT:
228+
def dark_gold(cls: type[CT]) -> CT:
228229
"""A factory method that returns a :class:`Colour` with a value of ``0xc27c0e``."""
229230
return cls(0xC27C0E)
230231

231232
@classmethod
232-
def orange(cls: Type[CT]) -> CT:
233+
def orange(cls: type[CT]) -> CT:
233234
"""A factory method that returns a :class:`Colour` with a value of ``0xe67e22``."""
234235
return cls(0xE67E22)
235236

236237
@classmethod
237-
def dark_orange(cls: Type[CT]) -> CT:
238+
def dark_orange(cls: type[CT]) -> CT:
238239
"""A factory method that returns a :class:`Colour` with a value of ``0xa84300``."""
239240
return cls(0xA84300)
240241

241242
@classmethod
242-
def brand_red(cls: Type[CT]) -> CT:
243+
def brand_red(cls: type[CT]) -> CT:
243244
"""A factory method that returns a :class:`Colour` with a value of ``0xED4245``.
244245
245246
.. versionadded:: 2.0
246247
"""
247248
return cls(0xED4245)
248249

249250
@classmethod
250-
def red(cls: Type[CT]) -> CT:
251+
def red(cls: type[CT]) -> CT:
251252
"""A factory method that returns a :class:`Colour` with a value of ``0xe74c3c``."""
252253
return cls(0xE74C3C)
253254

254255
@classmethod
255-
def dark_red(cls: Type[CT]) -> CT:
256+
def dark_red(cls: type[CT]) -> CT:
256257
"""A factory method that returns a :class:`Colour` with a value of ``0x992d22``."""
257258
return cls(0x992D22)
258259

259260
@classmethod
260-
def lighter_grey(cls: Type[CT]) -> CT:
261+
def lighter_grey(cls: type[CT]) -> CT:
261262
"""A factory method that returns a :class:`Colour` with a value of ``0x95a5a6``."""
262263
return cls(0x95A5A6)
263264

264265
lighter_gray = lighter_grey
265266

266267
@classmethod
267-
def dark_grey(cls: Type[CT]) -> CT:
268+
def dark_grey(cls: type[CT]) -> CT:
268269
"""A factory method that returns a :class:`Colour` with a value of ``0x607d8b``."""
269270
return cls(0x607D8B)
270271

271272
dark_gray = dark_grey
272273

273274
@classmethod
274-
def light_grey(cls: Type[CT]) -> CT:
275+
def light_grey(cls: type[CT]) -> CT:
275276
"""A factory method that returns a :class:`Colour` with a value of ``0x979c9f``."""
276277
return cls(0x979C9F)
277278

278279
light_gray = light_grey
279280

280281
@classmethod
281-
def darker_grey(cls: Type[CT]) -> CT:
282+
def darker_grey(cls: type[CT]) -> CT:
282283
"""A factory method that returns a :class:`Colour` with a value of ``0x546e7a``."""
283284
return cls(0x546E7A)
284285

285286
darker_gray = darker_grey
286287

287288
@classmethod
288-
def og_blurple(cls: Type[CT]) -> CT:
289+
def og_blurple(cls: type[CT]) -> CT:
289290
"""A factory method that returns a :class:`Colour` with a value of ``0x7289da``."""
290291
return cls(0x7289DA)
291292

292293
@classmethod
293-
def blurple(cls: Type[CT]) -> CT:
294+
def blurple(cls: type[CT]) -> CT:
294295
"""A factory method that returns a :class:`Colour` with a value of ``0x5865F2``."""
295296
return cls(0x5865F2)
296297

297298
@classmethod
298-
def greyple(cls: Type[CT]) -> CT:
299+
def greyple(cls: type[CT]) -> CT:
299300
"""A factory method that returns a :class:`Colour` with a value of ``0x99aab5``."""
300301
return cls(0x99AAB5)
301302

302303
@classmethod
303-
def dark_theme(cls: Type[CT]) -> CT:
304+
def dark_theme(cls: type[CT]) -> CT:
304305
"""A factory method that returns a :class:`Colour` with a value of ``0x36393F``.
305306
This will appear transparent on Discord's dark theme.
306307
@@ -309,31 +310,31 @@ def dark_theme(cls: Type[CT]) -> CT:
309310
return cls(0x36393F)
310311

311312
@classmethod
312-
def fuchsia(cls: Type[CT]) -> CT:
313+
def fuchsia(cls: type[CT]) -> CT:
313314
"""A factory method that returns a :class:`Colour` with a value of ``0xEB459E``.
314315
315316
.. versionadded:: 2.0
316317
"""
317318
return cls(0xEB459E)
318319

319320
@classmethod
320-
def yellow(cls: Type[CT]) -> CT:
321+
def yellow(cls: type[CT]) -> CT:
321322
"""A factory method that returns a :class:`Colour` with a value of ``0xFEE75C``.
322323
323324
.. versionadded:: 2.0
324325
"""
325326
return cls(0xFEE75C)
326327

327328
@classmethod
328-
def nitro_pink(cls: Type[CT]) -> CT:
329+
def nitro_pink(cls: type[CT]) -> CT:
329330
"""A factory method that returns a :class:`Colour` with a value of ``0xf47fff``.
330331
331332
.. versionadded:: 2.0
332333
"""
333334
return cls(0xF47FFF)
334335

335336
@classmethod
336-
def embed_background(cls: Type[CT], theme: str = "dark") -> CT:
337+
def embed_background(cls: type[CT], theme: str = "dark") -> CT:
337338
"""A factory method that returns a :class:`Color` corresponding to the
338339
embed colors on discord clients, with a value of:
339340

discord/enums.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,11 @@
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

2627
import types
2728
from collections import namedtuple
28-
from typing import (
29-
TYPE_CHECKING,
30-
Any,
31-
ClassVar,
32-
Dict,
33-
List,
34-
Optional,
35-
Type,
36-
TypeVar,
37-
Union,
38-
)
29+
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, Union
3930

4031
__all__ = (
4132
"Enum",
@@ -112,9 +103,9 @@ def _is_descriptor(obj):
112103
class EnumMeta(type):
113104
if TYPE_CHECKING:
114105
__name__: ClassVar[str]
115-
_enum_member_names_: ClassVar[List[str]]
116-
_enum_member_map_: ClassVar[Dict[str, Any]]
117-
_enum_value_map_: ClassVar[Dict[Any, Any]]
106+
_enum_member_names_: ClassVar[list[str]]
107+
_enum_member_map_: ClassVar[dict[str, Any]]
108+
_enum_value_map_: ClassVar[dict[Any, Any]]
118109

119110
def __new__(cls, name, bases, attrs, *, comparable: bool = False):
120111
value_mapping = {}
@@ -430,8 +421,8 @@ class AuditLogAction(Enum):
430421
auto_moderation_block_message = 143
431422

432423
@property
433-
def category(self) -> Optional[AuditLogActionCategory]:
434-
lookup: Dict[AuditLogAction, Optional[AuditLogActionCategory]] = {
424+
def category(self) -> AuditLogActionCategory | None:
425+
lookup: dict[AuditLogAction, AuditLogActionCategory | None] = {
435426
AuditLogAction.guild_update: AuditLogActionCategory.update,
436427
AuditLogAction.channel_create: AuditLogActionCategory.create,
437428
AuditLogAction.channel_update: AuditLogActionCategory.update,
@@ -488,7 +479,7 @@ def category(self) -> Optional[AuditLogActionCategory]:
488479
return lookup[self]
489480

490481
@property
491-
def target_type(self) -> Optional[str]:
482+
def target_type(self) -> str | None:
492483
v = self.value
493484
if v == -1:
494485
return "all"
@@ -608,7 +599,7 @@ class StickerFormatType(Enum):
608599

609600
@property
610601
def file_extension(self) -> str:
611-
lookup: Dict[StickerFormatType, str] = {
602+
lookup: dict[StickerFormatType, str] = {
612603
StickerFormatType.png: "png",
613604
StickerFormatType.apng: "png",
614605
StickerFormatType.lottie: "json",
@@ -900,13 +891,13 @@ class AutoModKeywordPresetType(Enum):
900891
T = TypeVar("T")
901892

902893

903-
def create_unknown_value(cls: Type[T], val: Any) -> T:
894+
def create_unknown_value(cls: type[T], val: Any) -> T:
904895
value_cls = cls._enum_value_cls_ # type: ignore
905896
name = f"unknown_{val}"
906897
return value_cls(name=name, value=val)
907898

908899

909-
def try_enum(cls: Type[T], val: Any) -> T:
900+
def try_enum(cls: type[T], val: Any) -> T:
910901
"""A function that tries to turn the value into enum ``cls``.
911902
912903
If it fails it returns a proxy invalid value instead.

0 commit comments

Comments
 (0)