On Thu, May 28, 2020 at 12:57 PM Paul Sokolovsky <pmis...@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.
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FZB5HUAP7AM3PZF4IC7MVEGDPTYJWPPH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to