python / python/cpython

Should we test `-X lazy_imports=all` more?

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

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

3.15 3.16 tests topic-lazy-imports type-bug
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Bug report

Bug description:

Inspired by #149321 I decided to see how well the test suite works with PYTHON_LAZY_IMPORTS=all / -X lazy_imports=all, which makes all imports lazy. It's nowhere near as bad as the none option that we're considering removing, but a few parts of the stdlib are broken, and it seems worth considering if we want to fix these.

Concrete issues I noticed:

  • #144957 breaks test_typing
  • test_unittest fails because unittest.main becomes a module instead of a function.
  • test_struct is broken because of a test that does exec("import struct") in a function; lazy imports are disallowed within functions. Similar issues affect test_enum, test_traceback, and test_future.
  • test_symtable is broken because it fills its _flags list by iterating over globals(), which means it starts containing lazy import marker objects. Similarly test_inspect breaks because it iterates over vars() of a module.

A few tests fail for legitimate reasons; test_compileall tests that an import triggers pyc compilation; test_builtin asserts that __import__ is used when in fact __lazy_import__ gets used.

Full list of failed modules on my machine:

test.test_future_stmt.test_future
test.test_inspect.test_inspect
test.test_pydoc.test_pydoc
test___all__
test__interpreters
test_builtin
test_capi
test_clinic
test_compileall
test_crossinterp
test_datetime
test_enum
test_generated_cases
test_idle
test_import
test_importlib
test_interpreters
test_json
test_lazy_import
test_struct
test_subprocess
test_symtable
test_tools
test_trace
test_traceback
test_tracemalloc
test_typing
test_unittest
test_xmlrpc
test_zipfile
CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs
  • gh-149739
  • gh-151090
  • gh-151105

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

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

はじめの一歩

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

調査の方向性

まず、リンクされている PR gh-149739、gh-151090、gh-151105 を確認し、その後 PYTHON_LAZY_IMPORTS=all または -X lazy_imports=all で失敗を再現します。指定された stdlib テストを調査し、lazy imports が原因の失敗と、意図された動作を検証しているテストを切り分けます。スコープについて合意し、関連するテストを修正するか、想定される失敗を文書化できれば完了です。

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

評価

技術スタック
python
領域
testing-qa
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

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

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