baxx
baxx

Reputation: 4725

How to include a particular directory for checking with mypy

In the mypy.ini file I have:

[mypy]
exclude = ['tests', 'build']

Which works alright as long as both of these directories exists - if one of them doesn't exist then I get the following error message:

There are no .py[i] files in directory '.'

I'm wondering if there's a way to exclude these directories without this error - or if not - if there's a way to explicitly tell mypy which directories it should check.

Upvotes: 0

Views: 3422

Answers (1)

jkr
jkr

Reputation: 19310

The issue is that exclude expects a regular expression in the INI file (see docs). I'm not great with regex, but you can start off with

[mypy]
exclude = (build|tests)

The documentation on the --exclude parameter is also useful (copied relevant parts below.

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. For instance, to avoid discovering any files named setup.py you could pass --exclude '/setup.py$'. Similarly, you can ignore discovering directories with a given name by e.g. --exclude /build/ or those matching a subpath with --exclude /project/vendor/. To ignore multiple files / directories / paths, you can provide the –exclude flag more than once, e.g --exclude '/setup.py$' --exclude '/build/'.

Also see https://github.com/python/mypy/issues/10310 for relevant discussion.

Upvotes: 1

Related Questions