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

setting line-length in pyproject.toml prevents Black from running in vim #1496

Closed
erikr opened this issue Jun 14, 2020 · 6 comments · Fixed by #1501
Closed

setting line-length in pyproject.toml prevents Black from running in vim #1496

erikr opened this issue Jun 14, 2020 · 6 comments · Fixed by #1501
Labels
T: bug Something isn't working

Comments

@erikr
Copy link

erikr commented Jun 14, 2020

Describe the bug

If line-length is set in pyproject.toml, running black in Vim fails and throws the following error:

'<=' not supported between instances of 'int' and 'str'

To Reproduce

The minimum example that reproduces the error for me:

├── pyproject.toml
└── test.py

The contents of pyproject.toml follow the same syntax as is provided by pyproject.toml in the black repo

[tool.black]
line-length = 79

The contents of test.py:

foo = 1

Running black in Vim on test.py throws the error:

'<=' not supported between instances of 'int' and 'str'

I can successfully run black on test.py outside of vim:

~/.vim/black/bin/black test.py

or

black test.py

If I comment out line-length in pyproject.toml, the error we see when calling black in Vim goes away:

[tool.black]
#line-length = 79

The problem seems to be how line-length is parsed and cast by black.

Expected behavior
black runs without errors, and utilizes the line-length value specified in pyproject.toml.

Environment (please complete the following information):

  • Version: 19.10b0
  • OS and Python version: macOS 10.15.5 and Python 3.8.3; also reproduced on Ubuntu 20.04 and Python 3.8.3.

Does this bug also happen on master?

To answer this, you have two options:

  1. Use the online formatter at https://black.now.sh/?version=master, which will use the latest master branch.

n/a

  1. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .;
    • make sure it's sane by running python -m unittest; and
    • run black like you did last time.

I get errors running python -m unittest but unsure related to this bug:

$ python -m unittest                                                                                                                                   
E....[2020-06-14 14:22:15,341] DEBUG: Using selector: EpollSelector (selector_events.py:59)
.[2020-06-14 14:22:15,342] DEBUG: Using selector: EpollSelector (selector_events.py:59)
.[2020-06-14 14:22:15,680] DEBUG: Using selector: EpollSelector (selector_events.py:59)
.[2020-06-14 14:22:15,682] DEBUG: Using selector: EpollSelector (selector_events.py:59)
[2020-06-14 14:22:15,683] INFO: 16 projects to run Black over (lib.py:311)
[2020-06-14 14:22:15,683] DEBUG: Using 2 parallel workers to run Black (lib.py:316)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on aioexabgp (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on attrs (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on bandersnatch (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on channels (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on django (lib.py:247)
[2020-06-14 14:22:15,684] INFO: Skipping django as it's disabled via config (lib.py:254)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on flake8-bugbear (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on hypothesis (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on pandas (lib.py:247)
[2020-06-14 14:22:15,684] INFO: Skipping pandas as it's disabled via config (lib.py:254)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on poetry (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on ptr (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on pyramid (lib.py:247)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on pytest (lib.py:247)
[2020-06-14 14:22:15,684] INFO: Skipping pytest as it's disabled via config (lib.py:254)
[2020-06-14 14:22:15,684] DEBUG: worker 0 working on sqlalchemy (lib.py:247)
[2020-06-14 14:22:15,685] DEBUG: worker 0 working on tox (lib.py:247)
[2020-06-14 14:22:15,685] DEBUG: worker 0 working on virtualenv (lib.py:247)
[2020-06-14 14:22:15,685] DEBUG: worker 0 working on warehouse (lib.py:247)
[2020-06-14 14:22:15,685] DEBUG: project_runner 0 exiting (lib.py:245)
[2020-06-14 14:22:15,685] DEBUG: project_runner 1 exiting (lib.py:245)
[2020-06-14 14:22:15,685] INFO: Analyzing results (lib.py:327)
.
======================================================================
ERROR: tests.test_black (unittest.loader._FailedTest)
----------------------------------------------------------------------
ImportError: Failed to import test module: tests.test_black
Traceback (most recent call last):
  File "/home/username/miniconda3/envs/ml4sts/lib/python3.8/unittest/loader.py", line 436, in _find_test_path
    module = self._get_module_from_name(name)
  File "/home/username/miniconda3/envs/ml4sts/lib/python3.8/unittest/loader.py", line 377, in _get_module_from_name
    __import__(name)
  File "/home/erik/black/tests/test_black.py", line 1766, in <module>
    class BlackDTestCase(AioHTTPTestCase):
NameError: name 'AioHTTPTestCase' is not defined


----------------------------------------------------------------------
Ran 9 tests in 0.348s

FAILED (errors=1)
@ichard26
Copy link
Collaborator

I can fix this, I introduced this regression trying to fix #1458.

@cooperlees
Copy link
Collaborator

@ichard26 Is this at all related to #1486 ?

@erikr
Copy link
Author

erikr commented Jun 15, 2020

@cooperlees Sounds suspiciously similar, and kudos to @keith's excellent choice of line-length, although 1) my issue was in context of Vim 8.1, not neovim, and 2) unsure if the exception he refers to is the same as what we're seeing here.

@ichard26
Copy link
Collaborator

ichard26 commented Jun 15, 2020 via email

@cooperlees
Copy link
Collaborator

cooperlees commented Jun 15, 2020

Agree, but should we merge the workaround for now and have your upcoming PR remove it if no longer needed?

@ichard26
Copy link
Collaborator

If I don't get a PR ready in 40 minutes, go ahead on merge the workaround. You know what I was trying to do yesterday with pipenv 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants