question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WPS335 rejects list-of-lists comprehensions

See original GitHub issue

What’s wrong

I’m trying to produce a list of lists but getting a false-positive warning:

WPS335 Found incorrect `for` loop iter type
 ([x] for x in (1, 2, 3))
 ^

Here is a code

[ l for l in
  ([x] for x in (1, 2, 3))
]

How it should be

It should be possible to produce the list of lists.

Flake8 version and plugins

{
  "dependencies": [],
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.8.8",
    "system": "Linux"
  },
  "plugins": [
    {
      "is_local": false,
      "plugin": "flake8-bandit",
      "version": "2.1.2"
    },
    {
      "is_local": false,
      "plugin": "flake8-broken-line",
      "version": "0.3.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-bugbear",
      "version": "20.11.1"
    },
    {
      "is_local": false,
      "plugin": "flake8-comprehensions",
      "version": "3.5.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-darglint",
      "version": "1.8.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-debugger",
      "version": "4.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-docstrings",
      "version": "1.6.0, pydocstyle: 6.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-eradicate",
      "version": "1.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8-string-format",
      "version": "0.3.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_commas",
      "version": "2.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_isort",
      "version": "4.0.0"
    },
    {
      "is_local": false,
      "plugin": "flake8_quotes",
      "version": "3.2.0"
    },
    {
      "is_local": false,
      "plugin": "mccabe",
      "version": "0.6.1"
    },
    {
      "is_local": false,
      "plugin": "naming",
      "version": "0.11.1"
    },
    {
      "is_local": false,
      "plugin": "pycodestyle",
      "version": "2.7.0"
    },
    {
      "is_local": false,
      "plugin": "pyflakes",
      "version": "2.3.1"
    },
    {
      "is_local": false,
      "plugin": "rst-docstrings",
      "version": "0.0.14"
    },
    {
      "is_local": false,
      "plugin": "wemake_python_styleguide",
      "version": "0.15.2"
    }
  ],
  "version": "3.9.2"
}

pip information

pip 20.2.3 from /home/astynax/Projects/hexlet/hexlet-exercise-kit/exercises/course-python-declarative-programming/python_declarative_programming_list_comprehensions_exercise/.venv/lib/python3.8/site-packages/pip (python 3.8) astor==0.8.1 attrs==21.2.0 bandit==1.7.0 darglint==1.8.0 docutils==0.17.1 eradicate==2.0.0 flake8==3.9.2 flake8-bandit==2.1.2 flake8-broken-line==0.3.0 flake8-bugbear==20.11.1 flake8-commas==2.0.0 flake8-comprehensions==3.5.0 flake8-debugger==4.0.0 flake8-docstrings==1.6.0 flake8-eradicate==1.0.0 flake8-isort==4.0.0 flake8-polyfill==1.0.2 flake8-quotes==3.2.0 flake8-rst-docstrings==0.0.14 flake8-string-format==0.3.0 gitdb==4.0.7 GitPython==3.1.14 isort==5.8.0 mccabe==0.6.1 pbr==5.6.0 pep8-naming==0.11.1 pycodestyle==2.7.0 pydocstyle==6.0.0 pyflakes==2.3.1 Pygments==2.9.0 PyYAML==5.4.1 restructuredtext-lint==1.3.2 six==1.16.0 smmap==4.0.0 snowballstemmer==2.1.0 stevedore==3.3.0 testfixtures==6.17.1 typing-extensions==3.10.0.0 wemake-python-styleguide==0.15.2

OS information

Ubuntu Linux 16.04

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
astynaxcommented, Jun 17, 2021

O, rly? This is just a minimal example! And why it’s invalid? One may want to iterate from the subcomprehension! Here is a real example if you want:

def non_empty_truths(list_of_lists):
    return [
        truths for truths in
        ([elem for elem in one_list if elem]  # noqa: WPS335
         for one_list in list_of_lists
         )
        if truths
    ]

And here should be the lists! Not tuples, not genexps, the lists!

0reactions
surya-kodeticommented, Jul 11, 2022

Hi there, I’m a newbie searching for an easy-to-solve issue this seems to be a good start for me. If this is still open, please guide me on this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Medicare Claims Processing Manual, Chapter 5 - CMS
this list for institutional claims to determine whether to pay under outpatient rehabilitation rules or whether payment rules for other types of service...
Read more >
Understanding list comprehension for flattening list of lists in ...
A for loop like that is a generator expression. It works exactly like a list comprehension except that it doesn't build a list....
Read more >
List Comprehension Python List of Lists - Finxter
What is this? Solution: Use two nested list comprehension statements, one to create the outer list of lists, and one to create the...
Read more >
Appendix D - CaseRite Software Instructions - Federal Motor Carrier ...
You may list a motor carrier official's written statement, ... Cylinder rejection and requalification [180.205(h)] ... Is comprehension tested?
Read more >
Protecting Confidential Legal Information Practice ... - Jenner & Block
Other courts have rejected the narrow interpretation of the privilege and protect virtually all communications from attorney to client.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found