Arguments to decorators as dependencies of the decorated function
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading mypy/server/deps.py and the fine-grained dependency logic, then reproduce the example with mypy --logical-deps example.py. Compare the generated .mypy_cache/3.6/example.deps.json with the decorator expression and determine whether decorator arguments should be recorded as dependencies of the decorated function.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100