Can this chained comparison really be simplified like PyCharm claims?
<p>I have a class with two integer attributes, <code>_xp</code> and <code>level</code>. I have a <code>while</code> loop which compares these two to make sure they're both positive:</p>

<pre><code>while self.level &gt; 0 and self._xp &lt; 0:
    self.level -= 1
    self._xp += self.get_xp_quota()
</code></pre>

<p>My PyCharm claims this can be simplified:</p>

<p><a href="http://i.stack.imgur.com/iLOGd.png" rel="nofollow"><img src="http://i.stack.imgur.com/iLOGd.png" alt="Simplify chained comparison"></a></p>

<p>Can it really? I want to make sure before reporting a bug to PyCharm.</p>

<p>I also found <a href="http://stackoverflow.com/questions/26502775/pycharm-simplify-chained-comparison">a similar question</a> but in that case the two variables were the same, mine has two different attributes.</p>

<p>IIRC, you could rewrite this as:</p>

<pre><code>while self._xp &lt; 0 &lt; self.level:
    self.level -= 1
    self._xp += self.get_xp_quota()
</code></pre>

<p>as per your reference above. It doesn't really matter that there's 2 different attributes or the same variable, ultimately you are simply comparing the values of each. </p>

<p>Let me know if that works.</p>

python python-3.x comparison pycharm