Bug: Windows guard in is_available() compares os.system (a function) to 'nt' — always False

Aperta Adatta ai principianti
#1,898 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
cli

Direzione di ricerca

Apri httpie/output/ui/man_pages.py e inizia da is_available(). Verifica il controllo attuale della piattaforma rispetto alla riproduzione mostrata nell’issue, quindi correggi la condizione per Windows. Il lavoro è completato quando Windows restituisce False prima di tentare di eseguire man, mentre il comportamento sulle piattaforme non Windows rimane invariato.

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

Descrizione

Description

In httpie/output/ui/man_pages.py, is_available() tries to short-circuit on Windows but the check is broken:

https://github.com/httpie/cli/blob/master/httpie/output/ui/man_pages.py#L21

def is_available(program: str) -> bool:
    if NO_MAN_PAGES or os.system == 'nt':
        return False
    ...

os.system is a built-in function object, so os.system == 'nt' is always False. The intended Windows guard never fires. The author almost certainly meant os.name == 'nt'.

Why it is wrong

  • os.system is <built-in function system>; comparing a callable to the string 'nt' is always False.
  • The correct, idiomatic Windows check is os.name == 'nt' (or sys.platform == 'win32').

Impact

On Windows the if NO_MAN_PAGES or os.system == 'nt': branch is dead code. The function does not short-circuit; instead it falls through to subprocess.run(['man', '1', program]). On a typical Windows install man is absent, so FileNotFoundError is raised and swallowed by the except Exception: return False, yielding the same observable result — but only by accident. If a man executable happens to be on PATH (e.g. Git Bash / WSL), HTTPie will attempt to render man pages on Windows, contrary to the intent of the guard. Also, relying on a swallowed exception for control flow is fragile.

Reproduction / verification

import os
print(os.system == 'nt')   # -> False (regardless of platform)
print(os.name == 'nt')     # -> True on Windows, 'posix' elsewhere

Suggested fix

import sys
...
def is_available(program: str) -> bool:
    if NO_MAN_PAGES or sys.platform == 'win32':
        return False
    ...

(Using sys.platform == 'win32' is the most robust Windows detector.)

Affected version

Current master (verified via git clone --depth 1).

Lingua principale
Python
Stelle
38.6k
Fork
4k
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 httpie/cli

Tutte le issue di httpie/cli

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.