python / python/typeshed

colorful how to handle dynamic types

Offen
#15,012 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

stubs: false positive
Vorherrschende Sprache
Python
Sterne
5.1k
Forks
2.1k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
82

Beschreibung

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>

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der README-Verwendung von colorful und dem im Issue beschriebenen dynamischen getattr-Verhalten; untersuche anschließend, wie die MODIFIERS-Kombinationen gebildet werden. Als erledigt würde ein abgestimmter Typing-Ansatz für dynamisch konstruierte Attribute gelten; im Issue werden keine Zieldatei und kein Test genannt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
developer-experience
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.