News for hackers. Stuff that matters.
Re:Lambdas and Functions in Python by xapata on Saturday June 16, 2018 @08:12PM (#17330211)
A lambda is no different in scoping rules than a regular function def. If you put a def in a loop, you'll find the same behavior.

Closures are only created for functions defined inside other functions. Thus the term non-local. They're variables that are neither local nor global.

Don't call it broken when it works as intended.

Re:Lambdas and Functions in Python by _sdegutis on Saturday June 16, 2018 @10:02PM (#17330550)
“Works as intended” but also “unintuitive to most users” is still broken. Disclaimer: I have hated python ever since falling out of love with it 8 years ago for reasons just like this one so I’m definitely biased.
Re:Lambdas and Functions in Python by xapata on Saturday June 16, 2018 @10:41PM (#17330633)
Since programming is a rapidly growing field and Python is the first language for many, I suspect that Python's scoping rules are in fact intuitive to most of its users. The ones who stumble are those with intuition built by some other language.
Re:Lambdas and Functions in Python by _sdegutis on Sunday June 17, 2018 @01:20AM (#17330999)
I'd argue that's the opposite. Python was the first dynamic language I learned. The scoping rules in Python didn't bother me because I didn't know any better, not because they're intuitive or well designed.
Re:Lambdas and Functions in Python by xapata on Sunday June 17, 2018 @10:26AM (#17332493)
Fair anecdote. I'll offer that in my experience teaching hundreds of students, most don't have trouble with the cascade from locals to globals to builtins, and quickly grasp that globals are looked up for each call. That closures work at all confuses the ones who are thinking carefully about local scope. I may have a biased sample of students, but I think it's decent evidence.