colorful how to handle dynamic types
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
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>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with colorful's README usage and the dynamic getattr behavior described in the issue, then examine how the MODIFIERS combinations are formed. Done would require an agreed typing approach for dynamically constructed attributes; the issue names no target file or test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100