-
Notifications
You must be signed in to change notification settings - Fork 40
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
IDE confusion around functions calling each other? #2635
Comments
Python typing expert @freider – any idea what's going on? |
Weird! Since the issue only happens if both functions call each other, I would guess this has something to do with pyright/pylance internals rather than the Modal types. Here is my best guess: pyright for some reason tries to determine the type of each function by looking inside the function body where there is a reference to the other function, which is then evaluated etc, causing a reference "loop" between the functions, which is probably terminated by pyright by just setting the type to "function". I'm not sure why pyright would actually need to look at the function body to determine types here though, maybe it does so just to type the body... Maybe it would help to add return type annotations (-> None) so it can determine return type directly from the signature? I don't know anything about pyright internals I'm afraid |
I just tested it, and adding the |
@freider annotating one of the functions as This was very weird and pretty hard to pin down. Thanks for validating and responding so quickly! 🙏 @erikbern @freider FWIW I only experienced this with Python 3.12, I switched my IDE to 3.11 and did not have this problem (though can't just switch my project ofc). Probably not worth leaving an issue on the Pyright repo or the Pylance repo since I can't come up with a MWE without using |
If modal function
fn_a
calls modal functionfn_b
, andfn_b
also callsfn_a
, pyright gets confused!The screenshot is from what I think is a MWE of this bug:
The program above ia valid and runs fine, but my IDE is having a problem with something. The issue is cryptic -
fn_a.remote
appears to the IDE to be undefined - but only when both functions call each other! If the functions don't both call each other, either one can call either one with.remote
with no issues.Using VS Code, Python 3.12.
The text was updated successfully, but these errors were encountered: