22
22
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23
23
DEALINGS IN THE SOFTWARE.
24
24
"""
25
+ from __future__ import annotations
25
26
26
27
import colorsys
27
28
import random
28
- from typing import Any , Optional , Tuple , Type , TypeVar , Union
29
+ from typing import Any , TypeVar
29
30
30
31
__all__ = (
31
32
"Colour" ,
@@ -115,31 +116,31 @@ def b(self) -> int:
115
116
""":class:`int`: Returns the blue component of the colour."""
116
117
return self ._get_byte (0 )
117
118
118
- def to_rgb (self ) -> Tuple [int , int , int ]:
119
+ def to_rgb (self ) -> tuple [int , int , int ]:
119
120
"""Tuple[:class:`int`, :class:`int`, :class:`int`]: Returns an (r, g, b) tuple representing the colour."""
120
121
return self .r , self .g , self .b
121
122
122
123
@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 :
124
125
"""Constructs a :class:`Colour` from an RGB tuple."""
125
126
return cls ((r << 16 ) + (g << 8 ) + b )
126
127
127
128
@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 :
129
130
"""Constructs a :class:`Colour` from an HSV tuple."""
130
131
rgb = colorsys .hsv_to_rgb (h , s , v )
131
132
return cls .from_rgb (* (int (x * 255 ) for x in rgb ))
132
133
133
134
@classmethod
134
- def default (cls : Type [CT ]) -> CT :
135
+ def default (cls : type [CT ]) -> CT :
135
136
"""A factory method that returns a :class:`Colour` with a value of ``0``."""
136
137
return cls (0 )
137
138
138
139
@classmethod
139
140
def random (
140
- cls : Type [CT ],
141
+ cls : type [CT ],
141
142
* ,
142
- seed : Optional [ Union [ int , str , float , bytes , bytearray ]] = None ,
143
+ seed : int | str | float | bytes | bytearray | None = None ,
143
144
) -> CT :
144
145
"""A factory method that returns a :class:`Colour` with a random hue.
145
146
@@ -161,146 +162,146 @@ def random(
161
162
return cls .from_hsv (rand .random (), 1 , 1 )
162
163
163
164
@classmethod
164
- def teal (cls : Type [CT ]) -> CT :
165
+ def teal (cls : type [CT ]) -> CT :
165
166
"""A factory method that returns a :class:`Colour` with a value of ``0x1abc9c``."""
166
167
return cls (0x1ABC9C )
167
168
168
169
@classmethod
169
- def dark_teal (cls : Type [CT ]) -> CT :
170
+ def dark_teal (cls : type [CT ]) -> CT :
170
171
"""A factory method that returns a :class:`Colour` with a value of ``0x11806a``."""
171
172
return cls (0x11806A )
172
173
173
174
@classmethod
174
- def brand_green (cls : Type [CT ]) -> CT :
175
+ def brand_green (cls : type [CT ]) -> CT :
175
176
"""A factory method that returns a :class:`Colour` with a value of ``0x57F287``.
176
177
177
178
.. versionadded:: 2.0
178
179
"""
179
180
return cls (0x57F287 )
180
181
181
182
@classmethod
182
- def green (cls : Type [CT ]) -> CT :
183
+ def green (cls : type [CT ]) -> CT :
183
184
"""A factory method that returns a :class:`Colour` with a value of ``0x2ecc71``."""
184
185
return cls (0x2ECC71 )
185
186
186
187
@classmethod
187
- def dark_green (cls : Type [CT ]) -> CT :
188
+ def dark_green (cls : type [CT ]) -> CT :
188
189
"""A factory method that returns a :class:`Colour` with a value of ``0x1f8b4c``."""
189
190
return cls (0x1F8B4C )
190
191
191
192
@classmethod
192
- def blue (cls : Type [CT ]) -> CT :
193
+ def blue (cls : type [CT ]) -> CT :
193
194
"""A factory method that returns a :class:`Colour` with a value of ``0x3498db``."""
194
195
return cls (0x3498DB )
195
196
196
197
@classmethod
197
- def dark_blue (cls : Type [CT ]) -> CT :
198
+ def dark_blue (cls : type [CT ]) -> CT :
198
199
"""A factory method that returns a :class:`Colour` with a value of ``0x206694``."""
199
200
return cls (0x206694 )
200
201
201
202
@classmethod
202
- def purple (cls : Type [CT ]) -> CT :
203
+ def purple (cls : type [CT ]) -> CT :
203
204
"""A factory method that returns a :class:`Colour` with a value of ``0x9b59b6``."""
204
205
return cls (0x9B59B6 )
205
206
206
207
@classmethod
207
- def dark_purple (cls : Type [CT ]) -> CT :
208
+ def dark_purple (cls : type [CT ]) -> CT :
208
209
"""A factory method that returns a :class:`Colour` with a value of ``0x71368a``."""
209
210
return cls (0x71368A )
210
211
211
212
@classmethod
212
- def magenta (cls : Type [CT ]) -> CT :
213
+ def magenta (cls : type [CT ]) -> CT :
213
214
"""A factory method that returns a :class:`Colour` with a value of ``0xe91e63``."""
214
215
return cls (0xE91E63 )
215
216
216
217
@classmethod
217
- def dark_magenta (cls : Type [CT ]) -> CT :
218
+ def dark_magenta (cls : type [CT ]) -> CT :
218
219
"""A factory method that returns a :class:`Colour` with a value of ``0xad1457``."""
219
220
return cls (0xAD1457 )
220
221
221
222
@classmethod
222
- def gold (cls : Type [CT ]) -> CT :
223
+ def gold (cls : type [CT ]) -> CT :
223
224
"""A factory method that returns a :class:`Colour` with a value of ``0xf1c40f``."""
224
225
return cls (0xF1C40F )
225
226
226
227
@classmethod
227
- def dark_gold (cls : Type [CT ]) -> CT :
228
+ def dark_gold (cls : type [CT ]) -> CT :
228
229
"""A factory method that returns a :class:`Colour` with a value of ``0xc27c0e``."""
229
230
return cls (0xC27C0E )
230
231
231
232
@classmethod
232
- def orange (cls : Type [CT ]) -> CT :
233
+ def orange (cls : type [CT ]) -> CT :
233
234
"""A factory method that returns a :class:`Colour` with a value of ``0xe67e22``."""
234
235
return cls (0xE67E22 )
235
236
236
237
@classmethod
237
- def dark_orange (cls : Type [CT ]) -> CT :
238
+ def dark_orange (cls : type [CT ]) -> CT :
238
239
"""A factory method that returns a :class:`Colour` with a value of ``0xa84300``."""
239
240
return cls (0xA84300 )
240
241
241
242
@classmethod
242
- def brand_red (cls : Type [CT ]) -> CT :
243
+ def brand_red (cls : type [CT ]) -> CT :
243
244
"""A factory method that returns a :class:`Colour` with a value of ``0xED4245``.
244
245
245
246
.. versionadded:: 2.0
246
247
"""
247
248
return cls (0xED4245 )
248
249
249
250
@classmethod
250
- def red (cls : Type [CT ]) -> CT :
251
+ def red (cls : type [CT ]) -> CT :
251
252
"""A factory method that returns a :class:`Colour` with a value of ``0xe74c3c``."""
252
253
return cls (0xE74C3C )
253
254
254
255
@classmethod
255
- def dark_red (cls : Type [CT ]) -> CT :
256
+ def dark_red (cls : type [CT ]) -> CT :
256
257
"""A factory method that returns a :class:`Colour` with a value of ``0x992d22``."""
257
258
return cls (0x992D22 )
258
259
259
260
@classmethod
260
- def lighter_grey (cls : Type [CT ]) -> CT :
261
+ def lighter_grey (cls : type [CT ]) -> CT :
261
262
"""A factory method that returns a :class:`Colour` with a value of ``0x95a5a6``."""
262
263
return cls (0x95A5A6 )
263
264
264
265
lighter_gray = lighter_grey
265
266
266
267
@classmethod
267
- def dark_grey (cls : Type [CT ]) -> CT :
268
+ def dark_grey (cls : type [CT ]) -> CT :
268
269
"""A factory method that returns a :class:`Colour` with a value of ``0x607d8b``."""
269
270
return cls (0x607D8B )
270
271
271
272
dark_gray = dark_grey
272
273
273
274
@classmethod
274
- def light_grey (cls : Type [CT ]) -> CT :
275
+ def light_grey (cls : type [CT ]) -> CT :
275
276
"""A factory method that returns a :class:`Colour` with a value of ``0x979c9f``."""
276
277
return cls (0x979C9F )
277
278
278
279
light_gray = light_grey
279
280
280
281
@classmethod
281
- def darker_grey (cls : Type [CT ]) -> CT :
282
+ def darker_grey (cls : type [CT ]) -> CT :
282
283
"""A factory method that returns a :class:`Colour` with a value of ``0x546e7a``."""
283
284
return cls (0x546E7A )
284
285
285
286
darker_gray = darker_grey
286
287
287
288
@classmethod
288
- def og_blurple (cls : Type [CT ]) -> CT :
289
+ def og_blurple (cls : type [CT ]) -> CT :
289
290
"""A factory method that returns a :class:`Colour` with a value of ``0x7289da``."""
290
291
return cls (0x7289DA )
291
292
292
293
@classmethod
293
- def blurple (cls : Type [CT ]) -> CT :
294
+ def blurple (cls : type [CT ]) -> CT :
294
295
"""A factory method that returns a :class:`Colour` with a value of ``0x5865F2``."""
295
296
return cls (0x5865F2 )
296
297
297
298
@classmethod
298
- def greyple (cls : Type [CT ]) -> CT :
299
+ def greyple (cls : type [CT ]) -> CT :
299
300
"""A factory method that returns a :class:`Colour` with a value of ``0x99aab5``."""
300
301
return cls (0x99AAB5 )
301
302
302
303
@classmethod
303
- def dark_theme (cls : Type [CT ]) -> CT :
304
+ def dark_theme (cls : type [CT ]) -> CT :
304
305
"""A factory method that returns a :class:`Colour` with a value of ``0x36393F``.
305
306
This will appear transparent on Discord's dark theme.
306
307
@@ -309,31 +310,31 @@ def dark_theme(cls: Type[CT]) -> CT:
309
310
return cls (0x36393F )
310
311
311
312
@classmethod
312
- def fuchsia (cls : Type [CT ]) -> CT :
313
+ def fuchsia (cls : type [CT ]) -> CT :
313
314
"""A factory method that returns a :class:`Colour` with a value of ``0xEB459E``.
314
315
315
316
.. versionadded:: 2.0
316
317
"""
317
318
return cls (0xEB459E )
318
319
319
320
@classmethod
320
- def yellow (cls : Type [CT ]) -> CT :
321
+ def yellow (cls : type [CT ]) -> CT :
321
322
"""A factory method that returns a :class:`Colour` with a value of ``0xFEE75C``.
322
323
323
324
.. versionadded:: 2.0
324
325
"""
325
326
return cls (0xFEE75C )
326
327
327
328
@classmethod
328
- def nitro_pink (cls : Type [CT ]) -> CT :
329
+ def nitro_pink (cls : type [CT ]) -> CT :
329
330
"""A factory method that returns a :class:`Colour` with a value of ``0xf47fff``.
330
331
331
332
.. versionadded:: 2.0
332
333
"""
333
334
return cls (0xF47FFF )
334
335
335
336
@classmethod
336
- def embed_background (cls : Type [CT ], theme : str = "dark" ) -> CT :
337
+ def embed_background (cls : type [CT ], theme : str = "dark" ) -> CT :
337
338
"""A factory method that returns a :class:`Color` corresponding to the
338
339
embed colors on discord clients, with a value of:
339
340
0 commit comments