News for hackers. Stuff that matters.
Re:JavaScript is Good, Actually by amelius on Wednesday May 16, 2018 @09:12AM (#17082078)
True. But nonlocal is relatively new.

Also nonlocal implies that other variables are local, which is not true. E.g., the following works without "nonlocal" keyword:

    counter = [0]

    def add(n):
      counter[0] += n

    add(1)
    add(2)
(This used to be my workaround.)
Re:JavaScript is Good, Actually by viraptor on Wednesday May 16, 2018 @09:59AM (#17082387)
Yup, relatively new. Only around since python 3.0, for the last 12 years ;-)
Re:JavaScript is Good, Actually by camel_Snake on Wednesday May 16, 2018 @10:18PM (#17088199)
nonlocal implies that you are reassigning a variable outside of the local scope.

Your example works because you are mutating an existing object, not reassigning a new one.

It's a disingenuous comparison IMO.