python / python/mypy

Arguments to decorators as dependencies of the decorated function

Aperta
#7,494 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

feature priority-2-low
Lingua principale
Python
Stelle
20.6k
Fork
3.3k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Forgive me (and please let me know) if I'm asking a question that is out of scope for this issue tracker. I'm trying to use mypy to do things it was not necessarily designed to do.

Specifically, I'm trying to use the fine-grained dependency mapping (see, e.g., mypy/server/deps.py) to find the source code that is needed for a given function. Concretely I'm running mypy --logical-deps example.py and then inspecting the dependency graphs generated in .mypy_cache/3.6/example.deps.json.

It seems to work pretty well for my purposes except that arguments to decorators are not listed as dependencies of the decorated function, e.g., in the following example

some_var = 1
@my_decorator(some_var)
def my_func(x):
    return x

Here, for my purpose, some_var is a dependency of my_func in the sense that it is needed to run my_decorator which returns the decorator for my_func. However, mypy does not list some_var as a dependency of my_func. If I understand the type checking correctly, this makes sense because it is not a dependency in terms of type checking; the type of some_var is relevant to type check the call to my_decorator, and the return type of my_decorator is relevant to type check the decoration, but there is no direct connection between some_var and my_func, right?

My question is if I have understood this correctly. This issue can be closed if someone knows this well enough to say "forget it kid, mypy is never going to solve your problem". My hope of course is that someone will say "yeah, that actually is a dependency, and here is the patch we need to write".

Thank you for your time.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia leggendo mypy/server/deps.py e la logica delle dipendenze a grana fine, quindi riproduci l'esempio con mypy --logical-deps example.py. Confronta il file .mypy_cache/3.6/example.deps.json generato con l'espressione del decoratore e determina se gli argomenti del decoratore debbano essere registrati come dipendenze della funzione decorata.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
devtools
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.