Lint check for missing commas in list literal?
Hi PyCQA, I've done a little searching but have not found a lint check for the following: [ 'a', 'b' 'c' ] evaluates to ['a', 'bc'] due to implicit string concatenation, but usually it's intended to be ['a', 'b', 'c']. If it is meant to be ['a', 'bc'] it's bad style. Guido recommends popular lint tools add a rule for this here: https://groups.google.com/forum/#!msg/python-ideas/jP1YtlyJqxs/FacZu-WK_9AJ If this check does not exist, I would be willing to create a flake8 plugin and add it to PyCQA. Regards, Razzi
I have written that check previously - specifically for a missing comma in a list-like context. I will see if I can find the code for it. On Mon, 24 Jul 2017, 12:01 Razzi Abuissa, <razzi@abuissa.net> wrote:
Hi PyCQA,
I've done a little searching but have not found a lint check for the following:
[ 'a', 'b' 'c' ]
evaluates to ['a', 'bc'] due to implicit string concatenation, but usually it's intended to be ['a', 'b', 'c']. If it is meant to be ['a', 'bc'] it's bad style.
Guido recommends popular lint tools add a rule for this here: https://groups.google.com/forum/#!msg/python-ideas/jP1YtlyJqxs/FacZu-WK_9AJ
If this check does not exist, I would be willing to create a flake8 plugin and add it to PyCQA.
Regards,
Razzi _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
@Daniel: Here's your code. https://twitter.com/lordmauve/status/718380935532670976 https://twitter.com/lordmauve/status/718449547786207233 I never made it into a pylint module :( On 24 July 2017 at 12:06, Daniel Pope <mauve@mauveweb.co.uk> wrote:
I have written that check previously - specifically for a missing comma in a list-like context. I will see if I can find the code for it.
On Mon, 24 Jul 2017, 12:01 Razzi Abuissa, <razzi@abuissa.net> wrote:
Hi PyCQA,
I've done a little searching but have not found a lint check for the following:
[ 'a', 'b' 'c' ]
evaluates to ['a', 'bc'] due to implicit string concatenation, but usually it's intended to be ['a', 'b', 'c']. If it is meant to be ['a', 'bc'] it's bad style.
Guido recommends popular lint tools add a rule for this here: https://groups.google.com/forum/#!msg/python-ideas/ jP1YtlyJqxs/FacZu-WK_9AJ
If this check does not exist, I would be willing to create a flake8 plugin and add it to PyCQA.
Regards,
Razzi _______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
_______________________________________________ code-quality mailing list code-quality@python.org https://mail.python.org/mailman/listinfo/code-quality
On Sun, Jul 23, 2017 at 2:13 PM, Razzi Abuissa <razzi@abuissa.net> wrote:
Hi PyCQA,
I've done a little searching but have not found a lint check for the following:
[ 'a', 'b' 'c' ]
evaluates to ['a', 'bc'] due to implicit string concatenation, but usually it's intended to be ['a', 'b', 'c']. If it is meant to be ['a', 'bc'] it's bad style.
Guido recommends popular lint tools add a rule for this here: https://groups.google.com/forum/#!msg/python-ideas/jP1YtlyJqxs/FacZu-WK_9AJ
If this check does not exist, I would be willing to create a flake8 plugin and add it to PyCQA.
Regards,
Razzi
Hi Razzi, This has been discussed here https://github.com/PyCQA/pycodestyle/issues/308 and there are a few plugins for Flake8 which do this: - https://pypi.org/project/flake8-commas/ - https://pypi.org/project/flake8-trailing-commas/ - https://pypi.org/project/flake8_strict/ You can find Flake8 plugins using this search on PyPI: https://pypi.org/search/?c=Framework+::+Flake8 Cheers, Ian
The trailing comma issue you linked is different, but it's good to know that can be detected as well! What I'd like to prevent is lists that look like ['A' 'B'] Which python interprets as ['AB'] In my experience ['A' 'B'] is a typo - ['A', 'B'] was intended. I discovered that the python AST module discards this kind of information - by the time the AST gets to flake8 it's impossible to tell there was ever implicit string concatenation, so there's nothing flake8 can do about this to my knowledge. If anybody is interested, here's a rough implementation as a standalone script that uses redbaron: https://github.com/razzius/redbaron-missing-comma-string-collection On Jul 24, 2017 4:07 AM, "Ian Stapleton Cordasco" < graffatcolmingov@gmail.com> wrote: On Sun, Jul 23, 2017 at 2:13 PM, Razzi Abuissa <razzi@abuissa.net> wrote:
Hi PyCQA,
I've done a little searching but have not found a lint check for the following:
[ 'a', 'b' 'c' ]
evaluates to ['a', 'bc'] due to implicit string concatenation, but usually it's intended to be ['a', 'b', 'c']. If it is meant to be ['a', 'bc'] it's bad style.
Guido recommends popular lint tools add a rule for this here: https://groups.google.com/forum/#!msg/python-ideas/jP1YtlyJq xs/FacZu-WK_9AJ
If this check does not exist, I would be willing to create a flake8 plugin and add it to PyCQA.
Regards,
Razzi
Hi Razzi, This has been discussed here https://github.com/PyCQA/pycodestyle/issues/308 and there are a few plugins for Flake8 which do this: - https://pypi.org/project/flake8-commas/ - https://pypi.org/project/flake8-trailing-commas/ - https://pypi.org/project/flake8_strict/ You can find Flake8 plugins using this search on PyPI: https://pypi.org/search/?c=Framework+::+Flake8 Cheers, Ian
participants (4)
-
Daniel Pope
-
Ian Stapleton Cordasco
-
James Broadhead
-
Razzi Abuissa