Allow to use function objects as singletons
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 30/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- python
- Ambito
- developer-experience
Direzione di ricerca
Inizia con l’esempio di singleton tramite factory function e il confronto con i singleton Enum nell’issue #668. Poiché nell’issue non sono indicati file di implementazione o test, individua innanzitutto dove typing rappresenta i valori singleton e come vengono attualmente gestiti gli oggetti funzione. Il lavoro è completo quando è stato stabilito se questi oggetti funzione possono essere accettati e rappresentati distintamente nelle annotazioni di tipo, con copertura per il caso in stile Element/Comment.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
I was trying to create some stubs for lxml library, but I encountered a function that depending on a function object it gets (as in specific function object - checked with identity check) only finds objects of specific type.
Here's a very simplified mock-up of it so that you can get some idea on what I mean (the typing for arg argument in the find function is incorrect and that's what I want to be able to type hint in some way):
from typing import Union
class _Element: ...
def Element() -> _Element: ...
class _Comment: ...
def Comment() -> _Comment: ...
def find(arg: Union[Element, Comment]) -> Union[_Element, _Comment]:
if arg is Element:
# only find _Element objects
elif arg is Element:
# only find _Comment objects
# this function should only accept `Element` and `Comment` function object
find(arg=Element)
So basically those functions serve as a singletons. Unfortunately typing.Union only allows Enums to work as singletons.
I am not entirely sure if this should be supported, usually the code could just be adjusted to use Enums, but in this case it will be used for type stubs so the code can't be edited. And to be honest, I am not sure if the code really needs editing in that case as if I didn't need typing for that library, I would say it's actually quite intuitive to use these factory functions as arguments in this case.
- Lingua principale
- Python
- Stelle
- 1.8k
- Fork
- 302
- Merge medio
- 23h
- PR unite (30g)
- 8
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
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 python/typing
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
-
topic: typing spec
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
-
topic: documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
topic: conformance tests topic: typing spec
Difficoltà 3/5 1-2 giorni Idoneità per principianti 72/100
Tutte le issue di python/typing
Issue simili
-
from:qa priority:P2 reliability tech-debt
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
spec-kitty/spec-kitty#4874 ·
-
fix: inaccuracy ⚠️
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
uabrc/uabrc.github.io#1255 · 1 commento ·
-
kind:bug needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
-
docs
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
ethereum-optimism/factory#64 ·