-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
Rhs in the form of "x" in "xxx" cannot infer the type #2010
Comments
Can you a bit more specific? What changes are you proposing? |
As I mentioned earlier, when I want to infer the type of the following code (the type of res), jedi cannot provide a result:
the reason of that is in the function
So why doesn't this branch return the following content:
Like the returned content in the previous
After making the modifications, it can infer the correct content and all existing unit tests can still pass |
@WutingjiaX thanks for reporting this, you're correct that Jedi currently doesn't infer a type here. I'd guess that the vast majority of uses of Note that There might also be a broader question of why this comparison is handled separately from the binary comparisons -- that could be useful to understand before we change it. (I can't immediately see any hints from the git history) It might be useful to understand a bit more about the use-case you have in mind here. Are you hitting an issue in a REPL? In a static code environment (perhaps an IDE)? An example test case might be a useful way to express this. @davidhalter does Jedi have an opinion about whether (in general) it's better to over-infer (i.e: guess a type that might not actually be there) or under-infer (i.e: miss types which are actually present)? |
@PeterJCLaw We generally over-infer. There is a simple reason for this: Autocompletion will always work in that case. In my Mypy/Jedi rewrite in Rust I'm trying to be very precise about types, because otherwise type-checking won't work and in this case (there I currently return @WutingjiaX Can you create a PR for this with a test? I feel like this is not very important, but I would happily merge your proposal. There's probably also a way to return |
@PeterJCLaw In a static code environment,but not an IDE。 I use plugins such as jedi, ruff, yapf, etc. to provide a language services at the top level for an AI application building platform (similiar to https://buildship.app/onboard/create-project). @davidhalter Sure,I‘m glad to create a PR for this。By the way,I have another similar type inference question, and I'm not sure if I should raise it in this issue or create a new one |
Feel free to open another issue if it's not related to the same thing. |
I found in _infer_comparison_part ,There are the following code snippets:
This will result in the inability to infer the type when cursor under the word res:
Why not return the following code like the previous branch?:
The text was updated successfully, but these errors were encountered: