CodeSOD: Answer the Questions on this Test

This post was originally published on this site

The Daily WTF

Jake works in Python. Python is a very flexible language, and Jake has some co-workers who like to exploit it as much as possible.

Specifically, they’re notorious for taking advantage of how any symbol can be redefined, as needed. Is int a built-in function? Yes. But what if you want to have a variable called int? No problem! Just go ahead and do it. Python won’t mind if you do int = int(5).

Sure, any linter will complain about the possible confusion, but do you really think this developer checks the linter output?

Now, this particular block of code happens to be a test, which Jake provided because it’s one of the more head-scratching versions of this pattern, but it’s representative of this approach.

def test_parameters(self, name, value, float = True): fcb = read_parameters(SERVER_ADDRESS) type = ” if valid_key(): type = ‘float’ if type == ‘float’: self.assertTrue(float) else: self.assertFalse(float)

To read the full article click on the 'post' link at the top.