option_manager.add_option ignores action when reading from config
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 35/100
調査の方向性
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
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PyCQA/flake8 のほかの issue
-
難易度 3/5 1〜2日 初心者へのやさしさ 76/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 45/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 42/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
似ている issue
-
bug server
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
sportsdataverse/sportsdataverse-py#641 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
googleapis/google-cloud-python#18532 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信