-
Notifications
You must be signed in to change notification settings - Fork 767
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
Default values in functions are always Unknown #2064
Comments
This seems like a bug in the hover provider; hovering works in the context outside of the default values, but not when inside a default value (and everything else works). |
Just to quick test, if you remove the decorator from the function, do you see that hover works? |
Which version of fastapi do you have installed? I just installed the latest published version (0.70.0), and I'm seeing a different behavior than you. Here's the code that I typed in from your screen shot, for reference: import fastapi
app = fastapi.FastAPI()
@app.route("/echo")
async def echo(text: str = fastapi.Query()):
return {"message": text} And here's what I see in the hover text. Unrelated to the issue you're reporting, I'm curious whether it's really your intent to use a function call inside of a default argument expression. That's generally a very dangerous thing to do because of the way default arguments work in Python. They are evaluated only once at the time the function definition is processed, not once for each time the function is called like in other languages. |
The issue persists no matter the decorator. I have also tried it with other libraries which use the same kind of behavior (typer and disnake). Both have the same problem. |
Also 0.70.0. this issue is not even specific to fastapi
At times the hover also works for me. However only when I have just typed the default value and haven't provided any arguments. After I do things like type arguments and then click elsewhere the hover always stops recognizing anything in the default value.
Yes I am completely aware of the risk. The default value being shared is actually ideal in my case. Recently a lot of libraries have been using this kind of syntax as a sort of parameter descriptor. I simply chose fastapi as it's the most known library with this syntax. |
Thanks for the additional context. I was able to repro the problem and find the underlying cause. This will be fixed in the next release. |
fixed in 2021.11.2 |
Environment data
Expected behavior
Default values should be properly detected
Actual behavior
If a default value in a function contains a call statement then the callable will always be Unknown.
Static type-checking however still works.
Logs
Code Snippet / Additional information
Defaults are always shown as Unknown (not even autocomplete works)
![image](https://user-images.githubusercontent.com/58166507/141169865-aac2f1a6-dde0-4eee-97a7-ac843999e880.png)
Pylance knows about the variables
![image](https://user-images.githubusercontent.com/58166507/141170031-237d64a2-0000-44c5-9302-d4091630cd42.png)
Type-checking still occurs
![image](https://user-images.githubusercontent.com/58166507/141170106-0f0f90f4-a3f6-4836-9182-2ee22b810fe6.png)
The text was updated successfully, but these errors were encountered: