News for hackers. Stuff that matters.
Re:Python Is Eating the World by jldugger on Monday August 12, 2019 @11:57AM (#20676603)
Well, this should have been caught as an unused assignment in static analysis. A whole ton of languages allow this situation, so I'm not gonna ding Python too hard for that one.

However, here's a related but different python gotcha:

    if foo(a):
        v = list(bar(a))
    for i in v:
        print i
In this example, v is only defined inside the if. Due to python's limited scopes, v is also valid outside the if, but only has an assignment when foo(a) is True. When foo(a) is false, the for loop throws an NameError. And yes, a coworker wrote code that accidentally implemented this antipattern, albeit much more spread out in the code base.

This is clearly a bug in the code, yet no static analysis tools I've tried have successfully discovered it. There's a bug in pylint that's been marked WONTFIX because it requires a wildly different implementation. At a language level, it feels weird that if blocks aren't a scope level for new variables. If you want to reference v outside the if loop, declare / assign it outside the loop first.

Re:Python Is Eating the World by joshuamorton on Monday August 12, 2019 @12:37PM (#20677064)
Indeed, as another user mentions, mypy will detect this issue, as will pytype, even without any annotations.
Re:Python Is Eating the World by jldugger on Monday August 12, 2019 @05:32PM (#20680253)
Interesting, I had not looked at these because I'm not interested in volunteering to add type notations to our code base.
Re:Python Is Eating the World by takeda on Monday August 12, 2019 @12:11PM (#20676757)
mypy was able to detect these kinds of issues for me
Re:Python Is Eating the World by marmaduke on Monday August 12, 2019 @03:35PM (#20679071)
I'm retty sure PyCharm catches that 2nd one with a warning