Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Usage message is displayed when not desired.

Aperta
#441 1 commento 4 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Riproduci il comportamento con l’esempio fornito fire_bug.py, inclusi i comandi concatenati e --help. Inizia tracciando i percorsi di esecuzione dei comandi e di visualizzazione dell’help di Python Fire; il lavoro sarà completato quando i comandi validi non stamperanno più help non richiesto, mentre le invocazioni senza comando e con --help forniranno informazioni utili sui comandi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
28.2k
Fork
1.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di google/python-fire

Tutte le issue di google/python-fire

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.