matches_gitignore: directory-only patterns in nested .gitignore not excluded under --exclude-gitignore
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug
matches_gitignore (mypy/modulefinder.py) fails to exclude a directory matched by a directory-only pattern (e.g. build/, node_modules/) when the pattern lives in a nested .gitignore (one in a scanned subdirectory), under --exclude-gitignore.
The trailing-slash decision uses the gitignore-relative path with a cwd-relative stat:
relative_path = os.path.relpath(subpath, gi_path)
if fscache.isdir(relative_path): # relative_path is relative to gi_path, but isdir resolves from cwd
relative_path = relative_path + "/"
When gi_path != cwd, relative_path doesn't resolve on disk, so isdir returns False, the / is never appended, and the directory-only pattern doesn't match — mypy then type-checks files the user intended to exclude.
The sibling matches_exclude in the same file does it correctly: it builds the match string with os.path.relpath(subpath) but calls fscache.isdir(subpath) on the original path.
To Reproduce
With --exclude-gitignore, a package dir containing a nested .gitignore whose content is sub/, where sub/ is a real subdirectory: mypy still checks files under sub/.
Expected Behavior
sub/ is excluded, matching git's own behavior for directory-only patterns.
Fix
Stat the original subpath (keep relative_path only for the spec match) — proposed in #21752.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en mypy/modulefinder.py, en matches_gitignore, y compara su manejo de rutas con el de matches_exclude, que está al mismo nivel. Ejecuta la reproducción descrita de --exclude-gitignore usando un .gitignore anidado que contenga sub/ y un subdirectorio real. Se considera terminado cuando el patrón que solo coincide con directorios excluye sub/ y los archivos que contiene, de acuerdo con el comportamiento de git.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- cli, tooling
- Tipo de issue
- Error
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Tranquilo
- Claridad
- Bien especificado
- Aptitud para principiantes
- 78/100