--exclude
regular expression leading "/" does not match in current directory
#19012
Labels
--exclude
regular expression leading "/" does not match in current directory
#19012
Uh oh!
There was an error while loading. Please reload this page.
This might be a documentation error, but I expect that the documentation does reflect intended behavior so I am reporting it here.
Bug Report
The documentation includes the following example for
--exclude
The implicature from the documentation (and just typical user expectation) is that
--exclude /build/
would exclude./build/b.py
and./some_dir/build/e.py
, while all others would be checked. However./build/b.py
is not excluded. But/build/
and/project/
will not match (and therefore will not exclude) abuild
orproject
directory directly in the current directory.Some examples will better illustrate.
To Reproduce
I created a directory structure
The Python files are all identical and contain
Then run
mypy --exclude '/build/' --config-file= .
in the directory that contains
a.py
.Expected Behavior
That is, I would expect that
build/b.py
would not be type checked.Actual Behavior
Note that
build/b.py
is erroneously type checked.Your Environment
mypy.ini
(and other config files): NoneUpdate: Now tested with mypy 1.15.0 and Python 3.13.3. The behavior remains as described above.
Obvious explanation
It appears that when the documentation was written, the expectation was that regular expression would have been tested against "
./build/b.py'", which would match as expected. But instead it is being tested against "
build/b.py`" which does not match the regular expressionAddition samples show what happens with different expressions
--exclude 'build'
correctly matches (excludes)build/b.py
, but incorrectly matches (excludes)extra_build/d.py
--exclude '\bbuild/'
does match what is expected for the structure I gave,But that would not help if I constructed a subdirectory with a name like
foo+build
.Although it definitely would be possible to construct a regular expression that does the right thing, it is going to be far from obvious how to do so, and unless there is some RE magic that I don't know or don't recall, it is not going to be pretty.
I have not looked at the source, but I expect that it will be easier to just prepend the OS specific version of "`./'" to what is being matched.
Meta
I am sure that I am not the first person to wish that we could go back in time and use some other form of file globbing here instead of regular expressions. But we have the history we have.
Also, I do recognize that it is much better and easier to manage exclude patterns in configuration files instead of on the command line, but I did have reason to use the command line, and so I encountered this issue.
The text was updated successfully, but these errors were encountered: