matches_gitignore: directory-only patterns in nested .gitignore not excluded under --exclude-gitignore

オープン 初心者向け
#21,760 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
静か
技術スタック
python
領域
cli, tooling

調査の方向性

mypy/modulefinder.py の matches_gitignore から始め、同じ階層にある matches_exclude のパス処理と比較します。sub/ と実際のサブディレクトリを含むネストされた .gitignore を使って、説明されている --exclude-gitignore の再現を実行します。ディレクトリ専用のパターンが git の動作と一致する形で sub/ とその配下のファイルを除外すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

bug
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.

主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。