D5915: Infer correct type from 'and' / 'or' expressions

Nicolás Alvarez noreply at phabricator.kde.org
Fri May 19 02:19:40 UTC 2017


nalvarez created this revision.
nalvarez added a project: KDevelop.
Restricted Application added a subscriber: kdevelop-devel.

REVISION SUMMARY
  kdev-python was assuming boolean operator expressions like `foo or bar` always returned `bool`, but Python defines them to always return the value of either variable depending on whether the first one is false-like. Thus, `someString or "bar"` should be interpreted as a string, not a boolean.
  
  This commit makes such boolean operator expressions have a type of `unsure(type(foo), type(bar))` instead. I also added new tests for this new behavior, and to ensure the good old `True or False` is still interpreted as a `bool`.

TEST PLAN
  Added new unit tests, and ensured old ones don't fail. Tested in the IDE with a simple .py file.

REPOSITORY
  R53 KDevelop: Python Support

BRANCH
  master

REVISION DETAIL
  https://phabricator.kde.org/D5915

AFFECTED FILES
  duchain/expressionvisitor.cpp
  duchain/tests/pyduchaintest.cpp

To: nalvarez, brauch
Cc: kdevelop-devel, geetamc, Pilzschaf, akshaydeo, surgenight, arrowdodger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170519/4f619fe6/attachment.html>


More information about the KDevelop-devel mailing list