From humble beginnings at an MSP, I've adventured through life as a sysadmin, into an engineer, and finally landed as a developer focused on fixing problems with automation.
It's not about consistency, it's about use-case. A list, tuple and set all solve different problems. Comprehensions should always be simple, otherwise you should be using a different construct that is readable.
Yes, you should use a linter, but almost any editor nowadays will catch the errors you point out and are not necessarily linting issues.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great article! Thanks a lot!
It is also important to lint your python code generally (and list comprehensions in particular). Because they can contain different problems:
x = (yield a for a in [1, 2, 3])will be not what you might think it is. Linter can catch this!x = [lambda y: a + y for a in [1, 2, 3]]will return4forx[0](1). And good linter will also catch this errorfor a in [1, 2, 3],for a in {1, 2, 3}andfor a in (1, 2, 3)forloop part has correct unpacking targetslist([x for x in [1, 2, 3]])I recommend to use wemake-python-styleguide. Check it out:
The strictest and most opinionated python linter ever!
wemake-python-styleguide
Welcome to the strictest and most opinionated python linter ever.
wemake-python-styleguideis actually a flake8 plugin with some other plugins as dependencies.Quickstart
You will also need to create a
setup.cfgfile with the configuration.We highly recommend to also use:
Running
This app is still just good old
flake8And it won't change your existing workflow.See "Usage" section in the docs for examples and integrations.
We also support Github Actions as first class-citizens Try it out!
What we are about
The ultimate goal of this project is to make all people write exactly the same
pythoncode.It's not about consistency, it's about use-case. A
list,tupleandsetall solve different problems. Comprehensions should always be simple, otherwise you should be using a different construct that is readable.Yes, you should use a linter, but almost any editor nowadays will catch the errors you point out and are not necessarily linting issues.