Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

option_manager.add_option ignores action when reading from config

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

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

評価

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

調査の方向性

tests/unit/test_option_manager.py から始め、特に test_action_cmdline と test_action_config を確認し、option_manager.add_option が config.load_config を通じて parse_from_config をどのように処理するかを追跡してください。設定された値がコマンドラインの値と同じように argparse.Action を呼び出し、回帰テストが通れば完了です。

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

説明

how did you install flake8?
pip install flake8

also when cloned from github master

unmodified output of flake8 --bug-report
{
  "platform": {
    "python_implementation": "CPython",
    "python_version": "3.10.8",
    "system": "Linux"
  },
  "plugins": [
    {
      "plugin": "mccabe",
      "version": "0.7.0"
    },
    {
      "plugin": "pycodestyle",
      "version": "2.10.0"
    },
    {
      "plugin": "pyflakes",
      "version": "3.0.1"
    }
  ],
  "version": "6.0.0"
}
describe the problem
what I expected to happen

my argparse.Action to be called regardless of if the parameter is specified on the command line or in the config

sample code

I implemented a test that reproduces the error. The first one passes, the second one doesn't.

from collections.abc import Sequence
from flake8.options import config

# always sets the value to bar regardless of what `values` is
class MyAction(argparse.Action):
    def __call__(
        self,
        parser: argparse.ArgumentParser,
        namespace: argparse.Namespace,
        values: Sequence[str] | None,
        option_string: str | None = None,
    ) -> None:
        setattr(namespace, self.dest, "bar")


def test_action_cmdline(optmanager):
    optmanager.add_option(
        "--my-option",
        parse_from_config=True,
        required=False,
        action=MyAction,
    )
    options = optmanager.parse_args(["--my-option", "foo"])
    assert options.my_option == 'bar'

def test_action_config(tmpdir):
    tmpdir.join("setup.cfg").write("[flake8]\nmy-option=foo\n")

    with tmpdir.as_cwd():
        cfg, cfg_dir = config.load_config(None, [], isolated=False)

    assert cfg.get("flake8", "my-option") == "bar"
commands ran
$ pytest -k test_action_ 
===================================== test session starts =====================================
platform linux -- Python 3.10.8, pytest-7.2.0, pluggy-1.0.0
rootdir: /home/h/Git/flake8, configfile: pytest.ini
collected 465 items / 463 deselected / 2 selected                                             

tests/unit/test_option_manager.py .F                                                    [100%]

========================================== FAILURES ===========================================
_____________________________________ test_action_config ______________________________________

tmpdir = local('/tmp/pytest-of-h/pytest-62/test_action_config0')

    def test_action_config(tmpdir):
        tmpdir.join("setup.cfg").write("[flake8]\nmy-option=foo\n")
    
        with tmpdir.as_cwd():
            cfg, cfg_dir = config.load_config(None, [], isolated=False)
    
>       assert cfg.get("flake8", "my-option") == "bar"
E       AssertionError: assert 'foo' == 'bar'
E         - bar
E         + foo

tests/unit/test_option_manager.py:243: AssertionError
========================= 1 failed, 1 passed, 463 deselected in 0.26s =========================

The value is foo, which it would be if there's no action specified, but it completely sidesteps calling the action completely.

主要言語
Python
スター
3.8k
フォーク
356
平均マージ
3時間 25分
マージ済み PR(30日)
5

環境構築

はじめの一歩

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

PyCQA/flake8 のほかの issue

PyCQA/flake8 の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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