On Thu, May 28, 2020 at 9:52 PM Paul Sokolovsky <pmis...@gmail.com> wrote:

> On Fri, 29 May 2020 05:33:57 +1000
> Chris Angelico <ros...@gmail.com> wrote:
> > People can already put all their main logic into a function. If you
> > want to unit-test your main function, that's the best way to do it.
>

Yes, and I want to make it easy, even tempting, to do so.


> > The trouble is, how much goes into main() and how much into if
> > __name__ == '__main__'? For example: Does your main function accept a
> > list of arguments, or does it look in sys.argv? Neither answer is
> > wrong.


I would suggest that people write another function (maybe main without the
dunder) if they want something a little more custom (e.g. more arguments)
and have `__main__` call that. Really the line `def __main__(...):` would
almost mechanically replace `if __name__ == '__main__':`, so it's easy to
look at existing projects to see how this could be handled. They could also
give `__main__` optional arguments.


> And that means the best way is to NOT force everyone across all
> > of Python to choose the same way - let people write their code their
> > way.
>
> Yes. Besides, "principled" and "uncompromising" linters and code
> formatters are recently on a rise, so hopefully everyone/every team can
> choose a style per their likes, without putting burden on all the other
> users of the language.
>

 There is no forcing, there is no burden. Certainly the `if` method should
remain for those who need it (e.g. to check in two separate blocks) and for
compatibility. It would just encourage better scoping. Besides, it would be
applicable in the vast majority of cases.
_______________________________________________
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/I4B7UX7NTWOGAZOBWXNT2RNC732XILZW/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to