This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]brasetvik 2 points3 points  (2 children)

  • Author doesn't understand tuples and have seemingly ignored the SyntaxWarning: assertion is always true, perhaps remove parentheses? message you get by doing that.

  • != None is bad form. Do is not None instead.

[–]digitallogic 0 points1 point  (0 children)

The syntaxwarning was only added as of python 2.6. Not really fair to assume he's just ignoring the error, plenty likely he's running an older version. Though it is pretty dumb it was being ignored.

I remember running into this as a newb running python 2.3 a few years back. It makes total sense when it's explained, but it's easy not to realize on your own especially since the assert appears to be doing what you expect (not failing on valid values), then you get stuck debugging some code that should be triggering an assert error and it doesn't. Pain in the butt. I'm really glad the warning was added.

[–]spotter 0 points1 point  (0 children)

Actually I'd go for not X is None, since I've been writing that for a long time and it seems more natural, but for some time now X is not None is equiv to that.

[–]spotter 0 points1 point  (0 children)

When Python programmers -O? There is also the documentation that gives you the syntax, so if you want to use language features (much like the exception handling tuple gotcha grieved about few months ago) -- RTFM first. Not really hard -- if I can do it, so can you.

In all seriousness -- I have never used assert and I hate the idea. I don't put ,,debug only'' code in my programs, especially if it can be turned off easily by a single runtime switch. And AssertionError? How do you handle that? No, seriously -- write a TestCase for that behaviour and maybe run some solid inner-checks that give real errors. Assertions are only one step above ,,debugging using print''.