Support `Any` as an alias for `object` to describe a default typeclass implementation
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 38/100
Direzione di ricerca
L’issue non indica file di implementazione né test. Inizia individuando la gestione alla base di @render.instance(object) e i test esistenti delle istanze di typeclass, quindi traccia come viene riconosciuto il default di object. Il lavoro è completato quando @render.instance(Any) si comporta in modo equivalente a @render.instance(object), mentre l’esempio usa l’implementazione di fallback.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Context. In order to define a default implementation (the one used if no other implementation matches), we currently have to write something like this:
from classes import typeclass
@typeclass
def render(data_value) -> str:
"""Render a data value nicely."""
@render.instance(int)
def _render_int(data_value: int) -> str:
return f'This is an integer: {data_value}'
@render.instance(object)
def _render_int(data_value: object) -> str:
return f'No idea what this is: {data_value}'
assert render('BADOOM') == 'No idea what this is: BADOOM'
(this script should be runnable as-is.)
Decision. Support Any as a special case to replace object:
@render.instance(Any)
def _render_int(data_value: Any) -> str: # type: ignore
return f'No idea what this is: {data_value}'
Consequences.
- Pro: The code will look a little bit more straightforward;
- Contra:
mypywith common settings might be unhappy aboutAnybeing used, but that can be silenced withtype: ignoreI suppose.
- Lingua principale
- Python
- Stelle
- 730
- Fork
- 30
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di dry-python/classes
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
dry-python/classes#496 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
dry-python/classes#494 ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 52/100
dry-python/classes#492 · 2 commenti ·
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
dry-python/classes#481 · 5 commenti · 4 reazioni ·
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 35/100
dry-python/classes#386 ·
Tutte le issue di dry-python/classes
Issue simili
-
Add: hunch Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
AbdelStark/awesome-typesafe#104 ·
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
DiamondLightSource/dodal#2211 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
openml/openml-python#1749 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
sipyourdrink-ltd/bernstein#6191 ·