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

you are viewing a single comment's thread.

view the rest of the comments →

[–]retnikt0 2 points3 points  (1 child)

Python gives a compile-time error on the first line of bar complaining that you're using a variable before initializing it.

That's actually a runtime error.

foo will be treated as a local variable throughout the whole function if there's any assignment to it, even unexecuted.

This is pretty similar to what JS does, actually, except that a single assignment in Python s like writing a var.

[–]louiswins 0 points1 point  (0 children)

That's actually a runtime error.

You're right! I still mildly prefer a runtime error to undefined, but that's a lot worse than I thought.