Skip to content

Doesn't honor extend-exclude for nested file #3754

Description

@asarkar

Describe the bug

Given the following configuration in pyproject.toml

[tool.black]
line-length = 120
extend-exclude = [
    '^(?:([^\/]+\/)+(?:test_.*\.py|.*_test\.py))$',
    '.github',
    '.mypy_cache',
    '.pytest_cache',
    'venv'
]

Black fails with the error:

Error: Invalid value for '--extend-exclude': Not a valid regular expression: unbalanced parenthesis at position 17

But this is a valid regex that's supposed to match any files starting or ending in test or files in a directory named test. For example, the following path matches the test directory:
myapp/folder/test/test_something.py

To Reproduce

I guess use the regex in a unit test that parses it?

Expected behavior

It should work. It would be even better if Black could use the extend-exclude list from flake8 or mypy, so that I don't have repeat it. The documentation only shows the max-line-length property.

Environment

  • Black's version: 23.3.0
  • OS: macOS Ventura 13.4.1, M1 chip
  • Python version: (CPython) 3.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions