pylint-dev / astroid

A common base representation of python source code for pylint and other projects
https://pylint.readthedocs.io/projects/astroid/en/latest/
GNU Lesser General Public License v2.1
528 stars 273 forks source link

Allow builtins to return more than one possible inference #521

Open brycepg opened 6 years ago

brycepg commented 6 years ago

Currently it looks like builtin inference only allows for one inference to be returned (https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_builtin_inference.py#L121).

If there are multiple possible inferences, currently the builtin result will be Uninferable. For future control flow I think it's important that the builtin brain at least support the possibility of multiple inference values.

PCManticore commented 6 years ago

This sounds reasonable but I wonder if you have any examples were this is needed today? At least right now all the builtin transforms should return just one potential value.

brycepg commented 6 years ago

On Wed, Mar 21, 2018 at 2:48 AM Claudiu Popa notifications@github.com wrote:

This sounds reasonable but I wonder if you have any examples were this is needed today? At least right now all the builtin transforms should return just one potential value.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PyCQA/astroid/issues/521#issuecomment-374867761, or mute the thread https://github.com/notifications/unsubscribe-auth/AAa9yLB5q6VHnPZIKznPbPjp-uWzRb0Cks5tghPJgaJpZM4SxNxH .

For example, if a value which inferred to both an instance of ClassA and ClassB was given to isinstance(value, ClassA) is like isinstance to infer [True, False] respectively (I would need to change isinstance inference)

I would like to use this to make conditionals narrow possible types let through to the possible inferred types inside a conditional. This will remove possible false positive no-member in pylint.

What do you think?

PCManticore commented 6 years ago

Thanks for the example, sounds good! Go for it.