pylint-bot / test

0 stars 0 forks source link

Add support for inference on IfExp nodes #236

Open pylint-bot opened 8 years ago

pylint-bot commented 8 years ago

Originally reported by: Laura Médioni (BitBucket: lmedioni, GitHub: @lmedioni?)


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.


pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


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.

pylint-bot commented 8 years ago

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


IMO it should be even simpler than that : return both possible values

pylint-bot commented 8 years ago

Original comment by Claudiu Popa (BitBucket: PCManticore, GitHub: @PCManticore?):


If we can infer the test, why not choosing the one we know is going to be taken? If not, yes, we can return both of them.

pylint-bot commented 8 years ago

Original comment by Sylvain Thénault (BitBucket: sthenault, GitHub: @sthenault?):


sounds good. I was thinking about the case where no context is provided