-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Decorators are sensitive to import cycle ordering #1303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Yeah, this is a known issue. |
I didn't see it documented elsewhere, though? |
See #481 (though it's not very specific). |
I marked this as a bug as there is no acceptable workaround right now, and this is a common thing. |
The following was copied from #481 because it's relevant here:
A fairly simple approach would to improve the lightweight type inference engine we have just for function decorators. Some ideas of additional things to support:
We could just "unwrap" the decorator type by taking the return type without checking the call otherwise.
We would just have to recognize if the return type has no type variables, which is easy, and then we can trivially infer the type of the decorated function. The current implementation lives in |
Let's make this a stretch goal for the 0.3.2. release. It's important, but we feel only Jukka understands it well enough to be able to fix it. If Jukka can't do it, we can release 0.3.2 without this and push it to the next milestone -- rather than hold up the release. |
I started working on this a while back but haven't had time to finish it. I'll see if the current branch is good enough to merge already, even if it's not complete. |
Infer more decorated function signatures during semantic analysis. Also add extra test cases for import cycles in general. Partially addresses #1303.
The original example now works, so I'm closing this. We can create new issues for remaining cases where decorators don't work. |
If we have two files:
test1.py:
test2.py:
Running
mypy test1.py test2.py
results in:test2.py:2: error: Cannot determine type of 'add'
Removing the
@deco
decorator from add or reversing the order of the files on the command line makes the error go away.The text was updated successfully, but these errors were encountered: