On 15 mars 07:50, Colin Morris wrote:
> If it were possible to check a little more carefully what's being asserted,
> then we could give a very specific message. As I understand it, we're
> warning against the case where someone is trying to assert some boolean
> expression along with a message to pass to the AssertionError's constructor
> ("assert x, msg"), but instead muddles the syntax and asserts a tuple
> ("assert (x, msg)"). If we could check that what's being asserted is a size
> 2 tuple literal, then we could give a more specific message like: "Assertion
> will always be true. Did you mean 'assert x, msg'?". Also, that could avoid
> some false positives since, I imagine, there are legitimate situations where
> you might want to assert some variable that holds a tuple of undetermined
> size (though 'assert len(sometuple) is not 0' might be more clear). I don't
> know if this is possible though--can the ASTNG tell whether a tuple is a
> literal or not?

if you get a Tuple instance as assert expression without infering, that's
a literal.
 
> Without those checks, we can't really be sure that the assertion will always
> be true, so the warning message would have to be a bit more noncommittal.
> Maybe something like:
> 
>  "Found assertion of tuple. Did you mean to do 'assert a, msg'?"
> or
> "Assertion of a non-empty tuple will always pass. Did you mean 'assert a,
> msg'?"

IMO we should:
* *not infer anything here*
* check for 2-uple and warn about potential misspelling of the assert statement
* check for literal true (eg True, not empty container, non zero number, etc..)
  of false (False, None, 0, etc...) expression and warn about always/never 
verified
  assertion
-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org

_______________________________________________
Python-Projects mailing list
Python-Projects@lists.logilab.org
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to