On Thu, May 28, 2020 at 12:57 PM Paul Sokolovsky <pmiscml@gmail.com> wrote:
And in all fairness, all good ideas already came to somebody else years
ago. There's https://www.python.org/dev/peps/pep-0299/ , successfully
rejected yet back in 2002. (So, feel free to use it in your own
environment/Python dialect.)

Thanks for the link. Pity it was rejected. I can think of one reason I'd quite like this beyond it being DRY and concise: I often see code written by others like this:

```
def foo(bar):
    print(bar)

if __name__ == '__main__':
    bar = 3
    foo(bar)
```

Now `bar` is both a local and global variable, which leads to both annoying IDE warnings and actual bugs. I think I encountered a bug related to this when someone used `eval()` (which was the right thing to do in this case) and didn't specify the namespaces correctly, but name shadowing made it seem like their code was correct.

Point is, I'd like something that encourages people to put all their `__main__` logic and variables into a function, rather than a module level conditional.