Skip to content
This repository was archived by the owner on Jan 13, 2024. It is now read-only.

Commit b7d5c53

Browse files
author
DirectiveAthena
committed
Fix: Removal of StrictType
1 parent 4d971bf commit b7d5c53

File tree

9 files changed

+74
-146
lines changed

9 files changed

+74
-146
lines changed

Tests/ColorObjects/test_HEX.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def CreateColor(hex_str = "#204080") -> HEX:
2525
def test_input(self):
2626
with self.assertRaises(TypeError):
2727
HEX(1)
28-
with self.assertRaises(TypeError):
28+
with self.assertRaises(ValueError):
2929
HEX(b"#123456")
3030
with self.assertRaises(ValueError):
3131
HEX("#123456789")

Tests/Functions/test_General.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,4 @@ def test_RoundHalfUp_Fail(self):
5454
with self.assertRaises(TypeError):
5555
RoundHalfUp((1,))
5656
with self.assertRaises(TypeError):
57-
RoundHalfUp([1,])
58-
59-
def test_StrictType(self):
60-
with self.assertRaises(TypeError):
61-
StrictType("a", (int,float))
62-
with self.assertRaises(TypeError):
63-
StrictType(1, str)
57+
RoundHalfUp([1,])

src/AthenaColor/Functions/General.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# - All -
1515
# ----------------------------------------------------------------------------------------------------------------------
1616
__all__ = [
17-
"Normalize", "RoundHalfUp","RoundToDecimals", "StrictType"
17+
"Normalize", "RoundHalfUp","RoundToDecimals"
1818
]
1919

2020
# ----------------------------------------------------------------------------------------------------------------------
@@ -29,9 +29,4 @@ def RoundToDecimals(value:int|float, decimals:int=None):
2929
return round(value, decimals)
3030

3131
def RoundHalfUp(value:int|float) -> int: # because Twidi didn't like RoundCorrectly :P
32-
return int(value + 0.5) # thanks for tedthetwonk for refinement
33-
34-
def StrictType(object_, type_) -> Any:
35-
if not isinstance(object_, type_):
36-
raise TypeError(f"{object_} was not of the type: {type_}")
37-
return object_
32+
return int(value + 0.5) # thanks for tedthetwonk for refinement

src/AthenaColor/Objects/Color/ColorSystem.py

Lines changed: 58 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from AthenaColor.InitClass import init
1414
from AthenaColor.Functions.Constraints import Constrain
1515
from AthenaColor.Functions.General import RoundHalfUp,RoundToDecimals
16-
from AthenaColor.Functions.General import StrictType
1716

1817
# ----------------------------------------------------------------------------------------------------------------------
1918
# - All -
@@ -67,9 +66,6 @@ def __round__(self, n=None) -> ColorSystem:
6766
def __iter__(self):
6867
return iter(self.export())
6968

70-
def __len__(self):
71-
return len(self.export())
72-
7369
def __hash__(self):
7470
return hash(self.export())
7571

@@ -193,30 +189,21 @@ def r(self) -> int:
193189
return self._r
194190
@r.setter
195191
def r(self, value: int|float):
196-
if init.roundUp:
197-
self._r = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
198-
else:
199-
self._r = round(Constrain(StrictType(value, (int,float)), 255))
192+
self._r = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
200193

201194
@property
202195
def g(self) -> int:
203196
return self._g
204197
@g.setter
205198
def g(self, value: int|float):
206-
if init.roundUp:
207-
self._g = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
208-
else:
209-
self._g = round(Constrain(StrictType(value, (int,float)), 255))
199+
self._g = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
210200

211201
@property
212202
def b(self) -> int:
213203
return self._b
214204
@b.setter
215205
def b(self, value: int|float):
216-
if init.roundUp:
217-
self._b = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
218-
else:
219-
self._b = round(Constrain(StrictType(value, (int,float)), 255))
206+
self._b = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
220207

221208
# ------------------------------------------------------------------------------------------------------------------
222209
# MAGIC Methods
@@ -235,7 +222,7 @@ class HEX(RGB):
235222
Inherits from RGB as this is just another notation for RGB values.
236223
"""
237224
def __init__(self, hex_value:str="#000000"):
238-
super().__init__(*hex_to_rgb(StrictType(hex_value, str)))
225+
super().__init__(*hex_to_rgb(hex_value))
239226

240227
# ------------------------------------------------------------------------------------------------------------------
241228
# MAGIC Methods
@@ -309,40 +296,29 @@ def r(self) -> int:
309296
return self._r
310297
@r.setter
311298
def r(self, value: int|float):
312-
if init.roundUp:
313-
self._r = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
314-
else:
315-
self._r = round(Constrain(StrictType(value, (int,float)), 255))
299+
self._r = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
316300

317301
@property
318302
def g(self) -> int:
319303
return self._g
320304
@g.setter
321305
def g(self, value: int|float):
322-
if init.roundUp:
323-
self._g = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
324-
else:
325-
self._g = round(Constrain(StrictType(value, (int,float)), 255))
306+
self._g = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
326307

327308
@property
328309
def b(self) -> int:
329310
return self._b
330311
@b.setter
331312
def b(self, value: int|float):
332-
if init.roundUp:
333-
self._b = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
334-
else:
335-
self._b = round(Constrain(StrictType(value, (int,float)), 255))
313+
self._b = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
314+
336315

337316
@property
338317
def a(self) -> int:
339318
return self._a
340319
@a.setter
341320
def a(self, value: int|float):
342-
if init.roundUp:
343-
self._a = RoundHalfUp(Constrain(StrictType(value, (int,float)), 255))
344-
else:
345-
self._a = round(Constrain(StrictType(value, (int,float)), 255))
321+
self._a = RoundHalfUp(Constrain(value, 255)) if init.roundUp else round(Constrain(value, 255))
346322
# ------------------------------------------------------------------------------------------------------------------
347323
# MAGIC Methods
348324
# ------------------------------------------------------------------------------------------------------------------
@@ -436,21 +412,21 @@ def h(self) -> int|float:
436412
return self._h
437413
@h.setter
438414
def h(self, value: int|float):
439-
self._h = RoundToDecimals(Constrain(StrictType(value, (int,float)), 360))
415+
self._h = RoundToDecimals(Constrain(value, 360))
440416

441417
@property
442418
def s(self) -> int|float:
443419
return self._s
444420
@s.setter
445421
def s(self, value: int|float):
446-
self._s = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
422+
self._s = RoundToDecimals(Constrain(value, 1))
447423

448424
@property
449425
def v(self) -> int|float:
450426
return self._v
451427
@v.setter
452428
def v(self, value: int|float):
453-
self._v = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
429+
self._v = RoundToDecimals(Constrain(value, 1))
454430

455431
# ------------------------------------------------------------------------------------------------------------------
456432
# MAGIC Methods
@@ -488,21 +464,21 @@ def h(self) -> int|float:
488464
return self._h
489465
@h.setter
490466
def h(self, value: int|float):
491-
self._h = RoundToDecimals(Constrain(StrictType(value, (int,float)), 360))
467+
self._h = RoundToDecimals(Constrain(value, 360))
492468

493469
@property
494470
def s(self) -> int|float:
495471
return self._s
496472
@s.setter
497473
def s(self, value: int|float):
498-
self._s = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
474+
self._s = RoundToDecimals(Constrain(value, 1))
499475

500476
@property
501477
def l(self) -> int|float:
502478
return self._l
503479
@l.setter
504480
def l(self, value: int|float):
505-
self._l = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
481+
self._l = RoundToDecimals(Constrain(value, 1))
506482

507483
# ------------------------------------------------------------------------------------------------------------------
508484
# MAGIC Methods
@@ -539,28 +515,28 @@ def c(self) -> int|float:
539515
return self._c
540516
@c.setter
541517
def c(self, value: int|float):
542-
self._c = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
518+
self._c = RoundToDecimals(Constrain(value, 1))
543519

544520
@property
545521
def m(self) -> int|float:
546522
return self._m
547523
@m.setter
548524
def m(self, value: int|float):
549-
self._m = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
525+
self._m = RoundToDecimals(Constrain(value, 1))
550526

551527
@property
552528
def y(self) -> int|float:
553529
return self._y
554530
@y.setter
555531
def y(self, value: int|float):
556-
self._y = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
532+
self._y = RoundToDecimals(Constrain(value, 1))
557533

558534
@property
559535
def k(self) -> int|float:
560536
return self._k
561537
@k.setter
562538
def k(self, value: int|float):
563-
self._k = RoundToDecimals(Constrain(StrictType(value, (int,float)), 1))
539+
self._k = RoundToDecimals(Constrain(value, 1))
564540

565541
# ------------------------------------------------------------------------------------------------------------------
566542
# MAGIC Methods
@@ -573,7 +549,7 @@ def __repr__(self) -> str:
573549
# Possible because we now have a __hash__ on any given ColorSystem class
574550
# needs to be placed here, as only after all the defining of all the colors, this map can be made
575551
_r_export = lambda r: r.export()
576-
_r_export_slice = lambda r: r.export()
552+
_r_export_RGBAtoRGB = lambda r: (r.r, r.g, r.b)
577553
_tuple3 = lambda r: (r,r,r)
578554
_tuple4 = lambda r: (r,r,r,r)
579555
_same = lambda r: r
@@ -582,81 +558,81 @@ def __repr__(self) -> str:
582558
RGB : {
583559
RGB: _r_export,
584560
HEX: _r_export,
585-
HSL: lambda r: hsl_to_rgb(*r.export()),
586-
HSV: lambda r: hsv_to_rgb(*r.export()),
587-
CMYK: lambda r: cmyk_to_rgb(*r.export()),
588-
RGBA: _r_export_slice,
589-
HEXA: _r_export_slice,
561+
HSL: lambda r: hsl_to_rgb(r.h, r.s, r.l),
562+
HSV: lambda r: hsv_to_rgb(r.h, r.s, r.v),
563+
CMYK: lambda r: cmyk_to_rgb(r.c,r.m,r.y,r.k),
564+
RGBA: _r_export_RGBAtoRGB,
565+
HEXA: _r_export_RGBAtoRGB,
590566
int: _tuple3,
591567
float: _tuple3,
592568
tuple: _same
593569
},
594570
HEX : {
595571
RGB: _r_export,
596572
HEX: _r_export,
597-
HSL: lambda r: hsl_to_rgb(*r.export()),
598-
HSV: lambda r: hsv_to_rgb(*r.export()),
599-
CMYK: lambda r: cmyk_to_rgb(*r.export()),
600-
RGBA: _r_export_slice,
601-
HEXA: _r_export_slice,
573+
HSL: lambda r: hsl_to_rgb(r.h, r.s, r.l),
574+
HSV: lambda r: hsv_to_rgb(r.h, r.s, r.v),
575+
CMYK: lambda r: cmyk_to_rgb(r.c,r.m,r.y,r.k),
576+
RGBA: _r_export_RGBAtoRGB,
577+
HEXA: _r_export_RGBAtoRGB,
602578
int: _tuple3,
603579
float: _tuple3,
604580
tuple: _same
605581
},
606582
HSL : {
607-
RGB: lambda r: rgb_to_hsl(*r.export()),
608-
HEX: lambda r: rgb_to_hsl(*r.export()),
583+
RGB: lambda r: rgb_to_hsl(r.r, r.g, r.b),
584+
HEX: lambda r: rgb_to_hsl(r.r, r.g, r.b),
609585
HSL: _r_export,
610-
HSV: lambda r: hsv_to_hsl(*r.export()),
611-
CMYK: lambda r: cmyk_to_hsl(*r.export()),
612-
RGBA: lambda r: rgb_to_hsl(*_r_export_slice(r)),
613-
HEXA: lambda r: rgb_to_hsl(*_r_export_slice(r)),
586+
HSV: lambda r: hsv_to_hsl(r.h, r.s, r.v),
587+
CMYK: lambda r: cmyk_to_hsl(r.c,r.m,r.y,r.k),
588+
RGBA: lambda r: rgb_to_hsl(r.r, r.g, r.b),
589+
HEXA: lambda r: rgb_to_hsl(r.r, r.g, r.b),
614590
int: _tuple3,
615591
float: _tuple3,
616592
tuple: _same
617593
},
618594
HSV : {
619-
RGB: lambda r: rgb_to_hsv(*r.export()),
620-
HEX: lambda r: rgb_to_hsv(*r.export()),
621-
HSL: lambda r: hsl_to_hsv(*r.export()),
595+
RGB: lambda r: rgb_to_hsv(r.r, r.g, r.b),
596+
HEX: lambda r: rgb_to_hsv(r.r, r.g, r.b),
597+
HSL: lambda r: hsl_to_hsv(r.h, r.s, r.l),
622598
HSV: _r_export,
623-
CMYK: lambda r: cmyk_to_hsv(*r.export()),
624-
RGBA: lambda r: rgb_to_hsv(*_r_export_slice(r)),
625-
HEXA: lambda r: rgb_to_hsv(*_r_export_slice(r)),
599+
CMYK: lambda r: cmyk_to_hsv(r.c,r.m,r.y,r.k),
600+
RGBA: lambda r: rgb_to_hsv(r.r, r.g, r.b),
601+
HEXA: lambda r: rgb_to_hsv(r.r, r.g, r.b),
626602
int: _tuple3,
627603
float: _tuple3,
628604
tuple: _same
629605
},
630606
CMYK : {
631-
RGB: lambda r: rgb_to_cmyk(*r.export()),
632-
HEX: lambda r: rgb_to_cmyk(*r.export()),
633-
HSL: lambda r: hsl_to_cmyk(*r.export()),
634-
HSV: lambda r: hsv_to_cmyk(*r.export()),
607+
RGB: lambda r: rgb_to_cmyk(r.r, r.g, r.b),
608+
HEX: lambda r: rgb_to_cmyk(r.r, r.g, r.b),
609+
HSL: lambda r: hsl_to_cmyk(r.h, r.s, r.l),
610+
HSV: lambda r: hsv_to_cmyk(r.h, r.s, r.v),
635611
CMYK: _r_export,
636-
RGBA: lambda r: rgb_to_cmyk(*_r_export_slice(r)),
637-
HEXA: lambda r: rgb_to_cmyk(*_r_export_slice(r)),
612+
RGBA: lambda r: rgb_to_cmyk(r.r, r.g, r.b),
613+
HEXA: lambda r: rgb_to_cmyk(r.r, r.g, r.b),
638614
int: _tuple4,
639615
float: _tuple4,
640616
tuple: _same
641617
},
642618
RGBA : {
643-
RGB: lambda r: (*r.export(), trnspDef),
644-
HEX: lambda r: (*r.export(), trnspDef),
645-
HSL: lambda r: (*hsl_to_rgb(*r.export()), trnspDef),
646-
HSV: lambda r: (*hsv_to_rgb(*r.export()), trnspDef),
647-
CMYK: lambda r: (*cmyk_to_rgb(*r.export()), trnspDef),
619+
RGB: lambda r: (r.r, r.g, r.b, trnspDef),
620+
HEX: lambda r: (r.r, r.g, r.b, trnspDef),
621+
HSL: lambda r: (*hsl_to_rgb(r.h, r.s, r.l), trnspDef),
622+
HSV: lambda r: (*hsv_to_rgb(r.h, r.s, r.v), trnspDef),
623+
CMYK: lambda r: (*cmyk_to_rgb(r.c,r.m,r.y,r.k), trnspDef),
648624
RGBA: _r_export,
649625
HEXA: _r_export,
650626
int: _tuple4,
651627
float: _tuple4,
652628
tuple: _same
653629
},
654630
HEXA : {
655-
RGB: lambda r: (*r.export(), trnspDef),
656-
HEX: lambda r: (*r.export(), trnspDef),
657-
HSL: lambda r: (*hsl_to_rgb(*r.export()), trnspDef),
658-
HSV: lambda r: (*hsv_to_rgb(*r.export()), trnspDef),
659-
CMYK: lambda r: (*cmyk_to_rgb(*r.export()), trnspDef),
631+
RGB: lambda r: (r.r, r.g, r.b, trnspDef),
632+
HEX: lambda r: (r.r, r.g, r.b, trnspDef),
633+
HSL: lambda r: (*hsl_to_rgb(r.h, r.s, r.l), trnspDef),
634+
HSV: lambda r: (*hsv_to_rgb(r.h, r.s, r.v), trnspDef),
635+
CMYK: lambda r: (*cmyk_to_rgb(r.c,r.m,r.y,r.k), trnspDef),
660636
RGBA: _r_export,
661637
HEXA: _r_export,
662638
int: _tuple4,

0 commit comments

Comments
 (0)