Skip to content

Crash/Regression - 0.930 no longer accepts multiline basic strings for exclude patterns in pyproject.toml #11825

Closed
@posita

Description

@posita

Crash Report

# pyproject.toml
[tool.mypy]
exclude = """(?x)(
  (^|/)build/
)"""

Anyone using a multiline basic string to define a regex for exclude such as above (source) will have to rewrite their regex to no longer span multiple lines:

# pyproject.toml
[tool.mypy]
exclude = "(?x)( (^|/)build/ )"

I believe this was working up through 0.921. I have not yet confirmed whether this has anything to do with #11329.

Traceback

Traceback (most recent call last):
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 948, in parse
    p = _parse_sub(source, state, flags & SRE_FLAG_VERBOSE, 0)
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 817, in _parse
    raise Verbose
sre_parse.Verbose

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "…/bin/mypy", line 8, in <module>
    sys.exit(console_entry())
  File "…/lib/python3.10/site-packages/mypy/__main__.py", line 12, in console_entry
    main(None, sys.stdout, sys.stderr)
  File "…/lib/python3.10/site-packages/mypy/main.py", line 70, in main
    sources, options = process_options(args, stdout=stdout, stderr=stderr,
  File "…/lib/python3.10/site-packages/mypy/main.py", line 1057, in process_options
    targets = create_source_list(special_opts.files, options, fscache)
  File "…/lib/python3.10/site-packages/mypy/find_sources.py", line 38, in create_source_list
    sub_sources = finder.find_sources_in_dir(path)
  File "…/lib/python3.10/site-packages/mypy/find_sources.py", line 112, in find_sources_in_dir
    if matches_exclude(
  File "…/lib/python3.10/site-packages/mypy/modulefinder.py", line 524, in matches_exclude
    if re.search(exclude, subpath_str):
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/re.py", line 200, in search
    return _compile(pattern, flags).search(string)
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/re.py", line 303, in _compile
    p = sre_compile.compile(pattern, flags)
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_compile.py", line 764, in compile
    p = sre_parse.parse(p, flags)
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 956, in parse
    p = _parse_sub(source, state, True, 0)
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 443, in _parse_sub
    itemsappend(_parse(source, state, verbose, nested + 1,
  File "/Library/Frameworks/MacPorts-20211130/Python.framework/Versions/3.10/lib/python3.10/sre_parse.py", line 836, in _parse
    raise source.error("missing ), unterminated subpattern",
re.error: missing ), unterminated subpattern at position 4

To Reproduce

mypy [--config-file=pyproject.toml] …

Your Environment

  • Mypy version used: 0.930
  • Mypy command-line flags: mypy [--config-file=pyproject.toml] …
  • Mypy configuration options from pyproject.toml: exclude (file is above)
  • Python version used: 3.10

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions