Python extractor reports parse errors for files no longer in the scanned commit

オープン
#22,579 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
48/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
python
領域
devtools

調査の方向性

まず、報告されたファイルが削除されたコミット 996e624 に対して Python extractor の診断を再現し、extractor がスキャンしたファイル集合とチェックアウト済みのコミットを比較します。構文のベースラインとして python -m py_compile を使用します。受け入れられたファイルで誤った parse エラーが発生せず、削除されたファイルが報告されなければ完了です。

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

説明

question

Setup

Observed behavior

CodeQL reports parse errors about two Python files. Here's a log sample (I've replaced my actual filenames with foo.py and bar.py):

Analysis produced the following diagnostic information:
##[group]Could not process some files due to syntax errors (2 results)
  * foo.py#L0C0:0: A parse error occurred while processing `foo.py`, and as a result this file could not be analyzed. Check the syntax of the file using the `python -m py_compile` command and correct any invalid syntax.
  * bar.py#L0C0:0: A parse error occurred while processing `bar.py`, and as a result this file could not be analyzed. Check the syntax of the file using the `python -m py_compile` command and correct any invalid syntax.
##[endgroup]

What I tried

  • I ran python -m py_compile on both files. This check completed without errors on Python 3.7, 3.8, 3.9, 3.10, 3.11, and 3.12.

  • I removed an old header from the files: # -*- coding: future_fstrings -*-. This header was a leftover from a Python 2 to Python 3 migration involving https://github.com/asottile-archive/future-fstrings. The warnings stayed. (I imagine, but am not sure, that this header caused the original parsing problem. These two files were the only ones in the repo that still had it.)

  • I checked the files for invisible characters and for a byte order mark. The only non-ASCII characters were some bullet characters inside one docstring. I replaced them with ASCII hyphens. The warnings stayed.

  • I replaced the full contents of both files with a single pass statement. The warnings stayed.

  • I deleted both files. The warnings stayed. I believe these logs confirm that CodeQL scanned the commit where I deleted the files (commit 996e624 in pull request 3584):

    ##[group]Checking out the ref
    [command]/usr/bin/git checkout --progress --force refs/remotes/pull/3584/head
    Note: switching to 'refs/remotes/pull/3584/head'.
    
    You are in 'detached HEAD' state. You can look around, make experimental
    changes and commit them, and you can discard any commits you make in this
    state without impacting any branches by switching back to a branch.
    
    If you want to create a new branch to retain commits you create, you may
    do so (now or later) by using -c with the switch command. Example:
    
      git switch -c <new-branch-name>
    
    Or undo this operation with:
    
      git switch -
    
    Turn off this advice by setting config variable advice.detachedHead to false
    
    HEAD is now at 996e624 bisect: blow away the whole python modules to see if codeql still complains [skip tests]
    ##[endgroup]
    
Expected behavior
  • CodeQL must not report parse errors for Python files that python -m py_compile accepts.
  • CodeQL must not report parse errors for files that do not exist in the scanned commit.
主要言語
CodeQL
スター
10.1k
フォーク
2.1k
平均マージ
2日 11時間
マージ済み PR(30日)
129

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

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

はじめの一歩

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

github/codeql のほかの issue

github/codeql の issue をすべて見る

似ている issue

DevTools の issue をもっと見る

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

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