Add support for inference on IfExp nodes

Issue #236 on hold
Laura Médioni
created an issue

It would be good to have support for inference on an IfExp node.

For example:

foo = True if something else False

An InferenceError is currently raised when calling inferred() on the right part of the assign node.

Comments (6)

  1. Claudiu Popa

    This is something that will be part of a larger implementation for understanding flow control in astroid (https://bitbucket.org/logilab/astroid/issues/213/draft-a-plan-for-having-control-flow), but I think we can start having an implementation for IfExp before that, since the challenges that come with a flow control understanding (path sensitiveness and things like that) don't come up at all for this example. As an implementation, it could be similar to the implementation of the bool builtin (astroid.brain.builtin_inference): infer what the test returns, call the result's bool_value method and depending on its result, return either one or the other branch.

  2. Log in to comment