Bug: Windows guard in is_available() compares os.system (a function) to 'nt' — always False
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 78/100
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.systemis<built-in function system>; comparing a callable to the string'nt'is alwaysFalse.- The correct, idiomatic Windows check is
os.name == 'nt'(orsys.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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di httpie/cli
-
new
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
bug new
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
Issue simili
-
货币战争手改优先级配置缺少列表元素类型校验(P3) Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Apertaarea: ci bug perceived difficulty: 3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 commento ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
ClickHouse/clickhouse-connect#1057 ·