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

Revert to treating exclude in .ini as single string #11881

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions docs/source/config_file.rst
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,19 @@ section of the command line docs.

.. confval:: exclude

:type: newline separated list of regular expressions
:type: regular expressions
posita marked this conversation as resolved.
Show resolved Hide resolved

A newline list of regular expression that matches file names, directory names and paths
A regular expression that matches file names, directory names and paths
which mypy should ignore while recursively discovering files to check.
Use forward slashes on all platforms.

.. code-block:: ini

[mypy]
exclude =
exclude = (?x)(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth it to note that the x flag causes whitespace, and lines beginning with #, to be ignored inside the pattern. A link to https://docs.python.org/3/library/re.html#re.X would save having to include further explanations.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like:

(?x) can be used as the first part of a regular expression. This corresponds to setting the re.X flag, which causes most witespace in the pattern to be ignored. Everything after an unescaped # is also ignored, allowing for comments. The Python re module has more information.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tinkered with it a bit. Let me know what you think.

Screen Shot 2022-01-01 at 19 12 39

The hyperlink goes to https://docs.python.org/3/library/re.html#re.X.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love it! Thanks for accepting feedback.

^file1\.py$
^file2\.py$
|^file2\.py$
)

For more details, see :option:`--exclude <mypy --exclude>`.

Expand Down
2 changes: 1 addition & 1 deletion mypy/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def check_follow_imports(choice: str) -> str:
'cache_dir': expand_path,
'python_executable': expand_path,
'strict': bool,
'exclude': lambda s: [p.strip() for p in s.split('\n') if p.strip()],
'exclude': lambda s: [s.strip()],
}

# Reuse the ini_config_types and overwrite the diff
Expand Down
7 changes: 4 additions & 3 deletions test-data/unit/cmdline.test
Original file line number Diff line number Diff line change
Expand Up @@ -1354,9 +1354,10 @@ b/bpkg.py:1: error: "int" not callable
# cmd: mypy .
[file mypy.ini]
\[mypy]
exclude =
abc
b
exclude = (?x)(
^abc/
|^b/
)
[file abc/apkg.py]
1()
[file b/bpkg.py]
Expand Down