[Plugins] Access value of a StarExpr
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 20.6k
- Fork
- 3.3k
- Metriche di merge delle PR
- Metriche PR in attesa
Descrizione
Hi folks, I'm trying to add support for StarExpr in a plugin but I'm unable to figure out the value of the StarExpr, here's an example of the code I want to make a plugin for:
def fake_union(name: str, types: Tuple[Types, ...]) -> Union[Types]:
...
UserErrors = (A, B)
Response = fake_union(types=(User, *UserErrors), name="Response")
I don't know if this is possible to figure out using MyPy, so far I was only able to fetch the Var definition, but not the type
def union_hook(ctx: DynamicClassDefContext) -> None:
types_expr = ctx.call.args[ctx.call.arg_names.index("types")]
assert isinstance(types_expr, TupleExpr)
for type_ in types_expr.items:
if isinstance(type_, StarExpr):
assert isinstance(type_.expr, NameExpr)
name = type_.expr.name
# how can I find the value of this expr?
print(name)
I made a repo with a full example here: https://github.com/patrick91/mypy-star-plugin
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.
Direzione di ricerca
Inizia con il repository di esempio del plugin e con gli entry point DynamicClassDefContext, TupleExpr, StarExpr e NameExpr mostrati nell’issue. Traccia come il plugin può ispezionare StarExpr per individuare UserErrors, quindi verifica che l’esempio possa accedere al valore espanso durante l’elaborazione dell’argomento types.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- devtools
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100