[Python-Dev] PEP 572 and assert (original) (raw)
Victor Stinner vstinner at redhat.com
Tue Jul 17 07:21:17 EDT 2018
- Previous message (by thread): [Python-Dev] PEP 572 and assert
- Next message (by thread): [Python-Dev] PEP 572 and assert
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2018-07-17 10:50 GMT+02:00 Serhiy Storchaka <storchaka at gmail.com>:
assert len(subdirs := list(path.iterdir())) == 0, subdirs
Does PEP 572 encourages writing such code, discourages this, or completely forbids?
If I understood correctly Guido, Python the language must not prevent developers to experiment various usage of assignement expressions. The f-string has a similar design: anything even f'{import("os").system("rm -rf /")}' is allowed.
It's more the role of linters like flake8 to warn against "bad practices".
I don't think that PEPs like f-string and assignment expressions must include coding styles.
Sure, f-string and assignment expressions allow to write surprising and bad code. But you don't them them to write crappy code :-)
I was strongly against f-string at the beginning because I immediately predicted that people will start to call functions (with side effects) in f-string... but I didn't see that happen. In fact, developers are reasonable and use f-string when it's appropriate and safe.
Victor
- Previous message (by thread): [Python-Dev] PEP 572 and assert
- Next message (by thread): [Python-Dev] PEP 572 and assert
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]