python / python/mypy

Wrong verbosity level when specified in both config file and command line.

Offen
#12,485 3 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

bug priority-2-low topic-configuration
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Bug Report

The verbosity level can be specified either on the command line (-v or -vv, etc.) or in the config file (verbosity = {number}). However, if specified in both places, what you get is the sum of the two levels.

To Reproduce

Place verbosity = 1 in the config file.
Call mypy -v ...

Expected Behavior

Verbosity 1, stderr shows LOG messages only.
Actual Behavior

Verbosity 2, stderr shows LOG messages and TRACE messages.

Your Environment

  • Mypy version used: 0.931
  • Mypy command-line flags: -v
  • Mypy configuration options from mypy.ini (and other config files): verbosity = 1

How to fix the bug
This is in main.py process_options().

497    general_group.add_argument(
498        '-v', '--verbose', action='count', dest='verbosity',
499        help="More verbose messages")
923    # Parse config file first, so command line can override.
924    parse_config_file(options, set_strict_flags, config_file, stdout, stderr)
937    # Parse command line for real, using a split namespace.
938    special_opts = argparse.Namespace()
939    parser.parse_args(args, SplitNamespace(options, special_opts, 'special-opts:'))

Before line 939, save options.verbosity, then set it to 0.
After line 939, if options.verbosity is 0 (meaning -v was not present), then set it to the earlier saved value.

Note: if verbosity is specified nonzero in the config file, there is no way to override this with verbosity 0 on the command line. You could add a no-verbose command line option to accomplish this.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne in main.py, in process_options() rund um das Parsen der Konfigurationsdatei und das im Issue beschriebene zweite Parsen der Kommandozeile. Reproduziere die Kombination aus verbosity = 1 und -v und untersuche anschließend, wie options.verbosity beibehalten und überschrieben wird. Als erledigt gilt die Änderung, wenn die Verbosity der Kommandozeile Vorrang hat, statt zum konfigurierten Wert addiert zu werden.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
cli
Issue-Typ
Bug
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Klar beschrieben
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.