Visitar URL original
Add --allow-empty-dir option by lomignet · Pull Request #12052 · python/mypy · GitHub
The Wayback Machine - https://web.archive.org/web/20250909151729/https://github.com/python/mypy/pull/12052
Skip to content

Conversation

lomignet
Copy link

Description

When searching for source files, an empty directory does no have
to be seen as error.
Default behaviour unchanged (empty dir is an error).

Context:
I use cookiecutter to generate skeletons of new repositories. This creates, among other things a scripts directory, where python scripts could end up. I thus want this directory to be mypy'ed by default, but no files there is not an issue.

The core of this change already existed, but it was not possible to pass the option from the cli. It now is.

Test Plan

In mypy.test.test_find_sources.SourceFinderSuite.test_find_sources_allow_empty_dir

Plus tested manually:

mkdir empty
mypy empty
# There are no .py[i] files in directory 'empty' + error code
mypy empty --disallow-empty-dir
# There are no .py[i] files in directory 'empty' + error code
mypy empty --allow-empty-dir
# Nothing to do?! 
# Success: no issues found in 0 source files + succesful exit code

When searching for source files, an empty directory does no have
to be seen as error.
Default behaviour unchanged (empty dir is an error).
@JelleZijlstra
Copy link
Member

This seems like a very specific thing to add an option for. Maybe we should just remove the error for empty directories.

@lomignet
Copy link
Author

This seems like a very specific thing to add an option for. Maybe we should just remove the error for empty directories.

It would make sense to me as well, but I didn't want to change the default behaviour. If this is the way forward, I'm happy to rewrite the PR, which should then become even simpler.

Let me know if maybe we should actually means let's :)

@JelleZijlstra
Copy link
Member

cc @hauntsaninja who touched this code last.

I'd lean towards allowing individual empty directories, but throwing an error if there are no Python files found across all the paths passed in.

@lomignet
Copy link
Author

I'd lean towards allowing individual empty directories, but throwing an error if there are no Python files found across all the paths passed in.

I would personally argue that no Python files means that there are no typing errors because there is no code which went wrong (but it could still be a cli option).

The actual use case to defend this is the same as what triggered me to send this PR. When setting up automatically a new repo, some directories (which can be individually mypy'ed because different part of a repo call for different level of strictness) could be empty, but the full CI street is already active. Mypy erroring out is misleading.

But I'll be happy to implement the final decision anyway.

@lomignet
Copy link
Author

@JelleZijlstra @hauntsaninja I would really welcome feedback :)

My favourite option so far is to have a check across all paths passed in (so allow individual empty dirs), with still an option to error out or not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants