Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ternary.py 1.2KB

1234567891011121314151617181920212223242526272829
  1. """Test for old tenrary constructs"""
  2. from UNINFERABLE import condition, true_value, false_value, some_callable # pylint: disable=import-error
  3. SOME_VALUE1 = true_value if condition else false_value
  4. SOME_VALUE2 = condition and true_value or false_value # [consider-using-ternary]
  5. SOME_VALUE3 = (false_value, true_value)[condition] # [consider-using-ternary]
  6. def func1():
  7. """Ternary return value correct"""
  8. return true_value if condition else false_value
  9. def func2():
  10. """Ternary return value incorrect"""
  11. return condition and true_value or false_value # [consider-using-ternary]
  12. def func3():
  13. """Ternary return value incorrect"""
  14. return (false_value, true_value)[condition] # [consider-using-ternary]
  15. SOME_VALUE4 = some_callable(condition) and 'ERROR' or 'SUCCESS' # [consider-using-ternary]
  16. SOME_VALUE5 = SOME_VALUE1 > 3 and 'greater' or 'not greater' # [consider-using-ternary]
  17. SOME_VALUE6 = (SOME_VALUE2 > 4 and SOME_VALUE3) and 'both' or 'not' # [consider-using-ternary]
  18. SOME_VALUE7 = 'both' if (SOME_VALUE2 > 4) and (SOME_VALUE3) else 'not'
  19. SOME_VALUE8 = SOME_VALUE1 and SOME_VALUE2 and SOME_VALUE3 or SOME_VALUE4
  20. SOME_VALUE9 = SOME_VALUE1 and False or SOME_VALUE2 # [simplify-boolean-expression]