Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Usage message is displayed when not desired.

Ouverte
#441 1 commentaire 4 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
45/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
python
Domaine
cli

Piste de recherche

Reproduisez le comportement avec l’exemple fourni fire_bug.py, y compris les commandes chaînées et --help. Commencez par suivre les chemins d’exécution des commandes et de rendu de l’aide de Python Fire ; le travail sera terminé lorsque les commandes valides n’afficheront plus d’aide intempestive, tandis que les invocations sans commande et avec --help fourniront des informations utiles sur les commandes.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
28.2k
Forks
1.5k
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de google/python-fire

Toutes les issues de google/python-fire

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.