A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2018-July/154654.html below:

[Python-Dev] PEP 572 and assert

[Python-Dev] PEP 572 and assertChris Angelico rosuav at gmail.com
Tue Jul 17 04:56:36 EDT 2018
On Tue, Jul 17, 2018 at 6:50 PM, Serhiy Storchaka <storchaka at gmail.com> wrote:
> Recently Barry shown an example:
>
>     assert len(subdirs := list(path.iterdir())) == 0, subdirs
>
> It looks awful to me. It looks even worse than using asserts for validating
> the user input. The assert has a side effect, and it depends on the
> interpreter option (-O). Even if subdirs is not used outside of the assert
> *now*, it is easy to introduce an error later, and it is hard to notice it
> if tests are not ran with the -O option regularly.
>
> Does PEP 572 encourages writing such code, discourages this, or completely
> forbids?
>

Asserts with side effects are already a bad idea. PEP 572 makes no
change to this. If you're putting any sort of side effects inside
assertions, you're playing with fire.

ChrisA
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4