colorful how to handle dynamic types
I played around with the new colorful types and there is a interesting problem.
Colorful takes full advantage of __getattr__ and im a bit out of ideas how to type this.
Common usage is (also seen in the readme):
import colorful as cf
print(cf.bold_white('Hello World'))
Where bold_white is dynamically build with the dynamically loadable color plate and a modifier.
Which makes this valid working python code:
import colorful as cf
print(cf.bold_underlined_struckthrough_italic_bold_red("typeshed"))
where the color from the pallet is red and the modifiers are separated by a _ and need to be out of a list of MODIFIERS but otherwise can be combined in any order and even be repeated.
MODIFIERS = {
'reset': (0, 0),
'bold': (1, 22),
'dimmed': (2, 22),
'italic': (3, 23),
'underlined': (4, 24),
'blinkslow': (5, 25),
'blinkrapid': (6, 25),
'inversed': (7, 27),
'concealed': (8, 28),
'struckthrough': (9, 29)
}
Is there any good solution to type something this dynamic?
Or is the only way to kinda allow everything after colorful.<anything>
If I understand how colorful works correctly, I fear the only possible solution is to basically copy the whole API of Colorful into colorful/__init__.pyi, including __getattr__, which means that indeed colorful.<anything> is allowed when it comes to types.