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

regression with path traversals in 21.5b2 #2389

Closed
pLeBlanc93 opened this issue Jul 21, 2021 · 3 comments
Closed

regression with path traversals in 21.5b2 #2389

pLeBlanc93 opened this issue Jul 21, 2021 · 3 comments
Labels
C: crash Black is crashing C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. C: packaging Installation and packaging of Black R: outdated Resolved or not relevant anymore. T: bug Something isn't working

Comments

@pLeBlanc93
Copy link

pLeBlanc93 commented Jul 21, 2021

Describe the bug

Traceback (most recent call last):
  File "C:\python\conda\envs\clone\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "C:\python\conda\envs\clone\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\python\conda\envs\clone\Scripts\black.exe\__main__.py", line 7, in <module>
  File "C:\python\conda\envs\clone\lib\site-packages\black\__init__.py", line 1130, in patched_main
    main()
  File "C:\python\conda\envs\clone\lib\site-packages\click\core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "C:\python\conda\envs\clone\lib\site-packages\click\core.py", line 782, in main
    rv = self.invoke(ctx)
  File "C:\python\conda\envs\clone\lib\site-packages\click\core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\python\conda\envs\clone\lib\site-packages\click\core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "C:\python\conda\envs\clone\lib\site-packages\click\decorators.py", line 21, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "C:\python\conda\envs\clone\lib\site-packages\black\__init__.py", line 421, in main
    stdin_filename=stdin_filename,
  File "C:\python\conda\envs\clone\lib\site-packages\black\__init__.py", line 518, in get_sources
    gitignore,
  File "C:\python\conda\envs\clone\lib\site-packages\black\files.py", line 223, in gen_python_files
    gitignore + get_gitignore(child) if gitignore is not None else None,
TypeError: unsupported operand type(s) for +: 'PathSpec' and 'PathSpec'

It looks like this was introduced with b8450b9#diff-1a5882c84fe4b3f18199a3e021822c1ea4bdc3f86952ea450c4db15d9387c7c3L215

To Reproduce

  1. Create a local folder black_test that has a file foo.py and an empty folder bar
  2. black C:/temp/black_test

Expected behavior
This works with black 21.5b1

Environment (please complete the following information):

  • Version: 21.5b2
  • OS and Python version: Windows/Python 3.7.10 x64

Does this bug also happen on main?

Haven't tested main yet, but it's also present on 21.7b0

Additional context

@ichard26 ichard26 added C: crash Black is crashing C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. C: packaging Installation and packaging of Black R: outdated Resolved or not relevant anymore. T: bug Something isn't working labels Jul 21, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Jul 21, 2021

Hey thanks for the bug report! This isn't actually a bug with Black itself, the problem lies in pathspec. I'm not entirely sure how you managed to get a pathspec that isn't 0.8.1 or higher since version 21.4b1 (containing this commit: a0b4e60) bumped Black's minimum pathspec requirement:

black/setup.py

Lines 75 to 77 in 1728bb4

"regex>=2020.1.8",
"pathspec>=0.8.1, <1",
"dataclasses>=0.6; python_version < '3.7'",

Why 0.8.1 specifically? It's the version that added addition support to PathSpec objects (see cpburnz/python-pathspec#43).


The reason why version 21.5b1 works is because nested .gitignore support didn't exist back then so addition support wasn't required. 21.5b2 was the first version with such support.

@pLeBlanc93
Copy link
Author

Ahh, that explains it. Thanks for quick response!

I also do not understand why pip install "black==21.7b0" did not upgrade pathspec. But confirmed that manually upgrading pathspec makes this issue non-repro. How interesting...

@bashtage
Copy link

bashtage commented Sep 6, 2021

Recent black requires pathspec>=0.9.0 (as indicated in setup.py) which was also not automatically installed for me when installing black.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing C: file collection Related to file collection (e.g. gitignore & cache) or file discovery and all of its configuration. C: packaging Installation and packaging of Black R: outdated Resolved or not relevant anymore. T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants