Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSP318 conflict with isort I001 and E128 #933

Closed
tbrlpld opened this issue Oct 23, 2019 · 5 comments · Fixed by #936
Closed

WSP318 conflict with isort I001 and E128 #933

tbrlpld opened this issue Oct 23, 2019 · 5 comments · Fixed by #936
Assignees
Labels
bug Something isn't working documentation Docs related task Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers pr-merged
Milestone

Comments

@tbrlpld
Copy link
Contributor

tbrlpld commented Oct 23, 2019

Bug report

What's wrong

There is no way of formatting a multi-line import without violating either WSP318 or I001 and E128.

from flask import (Blueprint, current_app, flash, g, redirect, render_template,
                   request, url_for)

Does not yield I001 and also not E128, but it does violate WSP318.

Fixing it so WSP318 is not violated creates violations against I001 and E128.

from flask import (Blueprint, current_app, flash, g, redirect, render_template,
    request, url_for)

How is that should be

WSP318 should respect visual indent (E128) and isort order (I001).

System information

$ pip list
Package                       Version
----------------------------- -------
astor                         0.8.0
attrs                         19.3.0
bandit                        1.6.2
colorama                      0.3.9
cycler                        0.10.0
docutils                      0.15.2
entrypoints                   0.3
eradicate                     1.0
flake8                        3.7.8
flake8-annotations-complexity 0.0.2
flake8-bandit                 2.1.2
flake8-broken-line            0.1.1
flake8-bugbear                19.8.0
flake8-builtins               1.4.1
flake8-coding                 1.3.2
flake8-commas                 2.0.0
flake8-comprehensions         2.2.0
flake8-debugger               3.2.0
flake8-docstrings             1.5.0
flake8-eradicate              0.2.3
flake8-executable             2.0.3
flake8-isort                  2.7.0
flake8-logging-format         0.6.0
flake8-pep3101                1.2.1
flake8-polyfill               1.0.2
flake8-print                  3.1.1
flake8-quotes                 2.1.0
flake8-rst-docstrings         0.0.11
flake8-string-format          0.2.3
gitdb2                        2.0.6
GitPython                     3.0.4
isort                         4.3.21
kiwisolver                    1.1.0
mando                         0.6.4
matplotlib                    3.1.1
mccabe                        0.6.1
numpy                         1.17.2
pbr                           4.0.2
pep8-naming                   0.8.2
pip                           19.3.1
pycodestyle                   2.5.0
pydocstyle                    4.0.1
pyflakes                      2.1.1
Pygments                      2.4.2
pyparsing                     2.4.2
python-dateutil               2.8.0
PyYAML                        5.1.2
radon                         2.4.0
restructuredtext-lint         1.3.0
setuptools                    39.0.1
six                           1.11.0
smmap2                        2.0.5
snowballstemmer               2.0.0
stevedore                     1.28.0
testfixtures                  6.10.0
typing-extensions             3.7.4
virtualenv                    15.2.0
virtualenv-clone              0.3.0
virtualenvwrapper             4.8.2
wemake-python-styleguide      0.12.5

Love the opinionated linting though ❤️ Just found it here! Awesome project. Definitely takes some useless thinking away from me.

@tbrlpld tbrlpld added the bug Something isn't working label Oct 23, 2019
@sobolevn
Copy link
Member

@tbrlpld thanks for raising this!

I guess, we should update the docs of WSP318 to link the isort multiline mode, so it would be clear for future users.

That's how it works. isort has multiple modes for multiline output. Our preferred mode is 3: https://github.com/wemake-services/wemake-python-styleguide/blob/master/setup.cfg#L71

And it is 100% compatible. All our code is checked for it. Example:

Considering your exact situation:

from flask import (
    Blueprint, 
    current_app, 
    flash, 
    g, 
    redirect, 
    render_template,
    request, url_for,
)

Would you like to update the docs with the link to the correct multiline_output_mode?

That's how it should be:

"""
...

This rule is also compatible with ``isort`` multiline output. 
You should set ``multi_line_output = 3`` setting.

See also:
     https://github.com/timothycrosley/isort#multi-line-output-modes
"""

@sobolevn sobolevn added documentation Docs related task Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers labels Oct 23, 2019
@sobolevn sobolevn added this to the Version 0.13 milestone Oct 23, 2019
@tbrlpld
Copy link
Contributor Author

tbrlpld commented Oct 23, 2019 via email

@sobolevn
Copy link
Member

Yes, we enforce the same configuration for everyone via nitpick: https://wemake-python-stylegui.de/en/latest/pages/usage/integrations/nitpick.html
Here's our isort config: https://raw.githubusercontent.com/wemake-services/wemake-python-styleguide/master/styles/isort.toml

Assigned you on this task, thanks a lot!

@tbrlpld
Copy link
Contributor Author

tbrlpld commented Oct 23, 2019

Ok, i'll update the documentation.

I also found a broken link, that is supposed to point to the isort.toml, but instead points to the flake8.toml.
I will update that as well, since the topic is related.

@tbrlpld
Copy link
Contributor Author

tbrlpld commented Oct 23, 2019

When running flake8 on the project it takes quite some time. That's why I tried flake8 -v for more output. This shows me a lot of warnings like this:

...
flake8.processor          ForkPoolWorker-4 142078 WARNING  Plugin requested optional parameter "search_current" but this is not an available parameter.
flake8.processor          ForkPoolWorker-4 142087 WARNING  Plugin requested optional parameter "builtins" but this is not an available parameter.
flake8.bugbear            ForkPoolWorker-2 142447 INFO     Optional warning B950 not present in selected warnings: ['E', 'F', 'W', 'C90']. Not firing it at all.
...

The same warnings repeat over and over. Am I doing something wrong?

Update: After letting the process go for a while, it ends with a Traceback:

...
flake8.bugbear            ForkPoolWorker-3 872034 INFO     Optional warning B950 not present in selected warnings: ['E', 'F', 'W', 'C90']. Not firing it at all.
flake8.processor          ForkPoolWorker-3 872040 WARNING  Plugin requested optional parameter "search_current" but this is not an available parameter.
flake8.processor          ForkPoolWorker-2 872156 WARNING  Plugin requested optional parameter "builtins" but this is not an available parameter.
flake8.processor          ForkPoolWorker-3 872194 WARNING  Plugin requested optional parameter "builtins" but this is not an available parameter.
flake8.checker            ForkPoolWorker-2 872521 CRITICAL Plugin F raised an unexpected exception
Traceback (most recent call last):
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/flake8/checker.py", line 435, in run_check
    return plugin["plugin"](**arguments)
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/flake8/plugins/pyflakes.py", line 94, in __init__
    file_tokens=file_tokens,
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 673, in __init__
    self.runDeferred(self._deferredFunctions)
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 710, in runDeferred
    handler()
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 1529, in <lambda>
    self.deferFunction(lambda: self.handleDoctests(node))
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 1156, in handleDoctests
    self.addBinding(None, Builtin('_'))
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 878, in addBinding
    parent_stmt = self.getParent(value.source)
  File "/Users/tibor/dev/wemake-python-styleguide/venv/lib/python3.6/site-packages/pyflakes/checker.py", line 816, in getParent
    node = node.parent
AttributeError: 'NoneType' object has no attribute 'parent'
"pyflakes" failed during execution due to "'NoneType' object has no attribute 'parent'"
Run flake8 with greater verbosity to see more details
flake8.main.application   MainProcess 872665 INFO     Finished running
flake8.main.application   MainProcess 872670 INFO     Reporting errors
flake8.main.application   MainProcess 873385 INFO     Found a total of 0 violations and reported 0

Is this the expected behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Docs related task Hacktoberfest Hactoberfest fun! help wanted Extra attention is needed level:starter Good for newcomers pr-merged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants