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

Usage message is displayed when not desired.

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

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

評価

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

調査の方向性

提供された fire_bug.py の例を使って、連結されたコマンドと --help を含む動作を再現してください。まず、Python Fire のコマンド実行とヘルプ表示の経路を追跡します。完了の条件は、有効なコマンドが要求されていないヘルプを表示しなくなり、コマンドなしおよび --help の呼び出しで有用なコマンド情報が提供されることです。

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

説明

When I build a class with methods that can be chained (they return self), I find that the "commands" help message is written out even when I provide commands with proper arguments and the commands are executed. Here is the code

from __future__ import annotations
from fire import Fire


class Foo:
    def act(self, x: int) -> Foo:
        """
        Act for some number of minutes.
        Parameters
        ----------
        x : int
            The number of minutes to act.
        """

        print("act", x, "minute(s)")
        return self

    def rest(self, x: int, y: str = "hours") -> Foo:
        """
        Rest for a while.
        Parameters
        ----------
        x : int
            The time to rest.
        y : str
            The units of x. The default is hours.
        """

        print("rest", x, y)
        return self


if __name__ == "__main__":
    Fire(Foo)

If I run this as python fire_bug.py, I get the help output I expect, which is

NAME
    fire_bug.py act 1

SYNOPSIS
    fire_bug.py act 1 COMMAND

COMMANDS
    COMMAND is one of the following:

     act
       Act for some number of minutes.

     rest
       Rest for a while.

If I run this as python fire_bug.py act 1, I unexpectedly get the help output

NAME
    fire_bug.py act 1

SYNOPSIS
    fire_bug.py act 1 COMMAND

COMMANDS
    COMMAND is one of the following:

     act
       Act for some number of minutes.

     rest
       Rest for a while.

followed by the output I expect, which is

act 1 minute(s)

If run this as python fire_bug.py act 1 rest 9, I again unexpectedly get the help output

NAME
    fire_bug.py act 1 rest 9

SYNOPSIS
    fire_bug.py act 1 rest 9 - COMMAND

COMMANDS
    COMMAND is one of the following:

     act
       Act for some number of minutes.

     rest
       Rest for a while.

followed by the output I expect, which is

act 1 minute(s)
rest 9 hours

If I add a __str__ method to the class that returns "\b", I don't get the unexpected messages, but I also don't get a help message if I run python fire_bug.py.

As a general observation, running python fire_bug.py --help does not produce useful output. The output is

NAME
    fire_bug.py

SYNOPSIS
    fire_bug.py -

The output I would expect would be the output I get when I run python fire_bug.py. I am aware that if I have an __init__ method with arguments that the information about those arguments will be displayed, but separating the two sets of information in this way is quite counterintuitive. Both sets of information should be provided when running with no command and when running with only a --help argument.

主要言語
Python
スター
28.2k
フォーク
1.5k
PR マージ指標
30日以内にマージされた PR はありません

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

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

はじめの一歩

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

google/python-fire のほかの issue

google/python-fire の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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