-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
Improve inferred
interface
#2065
Comments
I think this make sense if we want to decreases false positives in pylint. It should not help too much because we're supposed not to raise when we can't infer already. When you say you tested did you mean you ran pylint's tests with the modified code ? I would be very surprised if it did not lead at least to some behavior changes. |
Yes, pylint and astroid test. I created PR to run tests in astroid. |
I'm not sure if I agree with the proposal. It feels like we are hiding results with magic that makes the behaviour less explicable. I don't think we should support this a public API. |
Well, I am ok if you reject it. But the problem still remains. In a Python typing system, the expression Of course, we can still keep the result of such inference randomly, but then issues similar to pylint-dev/pylint#7565 are unable to resolve. The first change that I considered while solving pylint-dev/pylint#7565 was to make this sorting right here. But then I thought: "wait, that should be in interface of
Summing up:
|
This is why we have
I think we shouldn't prioritize anything. We should either check that all results are of the same type or indicate that there is ambiguity. See
That explanation of not using
As said above, let's not do determinism but allow the user/library to determine the degree of determinism they want.
Use
This is a different issue again. It is expected that code that isn't available on Python |
It seems that this is what I overlooked.
Yes, I know it, but the inferred types (union of types) are still subject to typing laws, but I see you are aware of it (
It makes sense. Although, from this sentence it can be concluded that pylint will never support a "compatibility" library. By compatibility, I mean a lot of if-statements with Anyway, I am closing this issue along with PR, since this I have no more concerns. Thanks for a clean explanation! |
You could look into using
Thanks for the compliment! And thank you for opening the issue and engaging in a meaningful discussion. Even though we haven't helped you directly it is also good for us to see how people use |
Steps to reproduce
Current behavior
This code fail, because it
inferred
function return inferred values in order of its occurrence in analyzed code.Expected behavior
A
NodeNG
interface should have a method to take only one best inferred value.Considered changes
inferred
find any nonUninferable
value, then remove allUninferable
from returning list:inferred
before returning, we can sort values with most "valuable" values at the beginning:def inferred_best(self) -> InferenceResult
toNodeNG
, where it returns single inferred value, possibly avoid Uninferable.I think the 3rd option is the best and I prepared some code, but before creating pull request I want to know others opinions.
Rationale
It is important for other functionality (especially in pylint-dev/pylint#7565 - where inferred value is considered as
Uninferable
despite having another better value).inferred()[0]
is a frequent code (about 60 occurrences in astroid and pylint), so it seems reasonable to replace it withinferred_best()
- I tested such a change locally, and it seems ok.python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
output5.16.0dev0
The text was updated successfully, but these errors were encountered: