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

Open Beginner friendly
#1,898 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
cli

Research direction

Open httpie/output/ui/man_pages.py and start at is_available(). Verify the current platform check against the reproduction shown in the issue, then correct the Windows guard. Done means Windows returns False before attempting to run man, while non-Windows behavior remains unchanged.

Written by the indexing model from the issue text.

Description

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).

Dominant language
Python
Stars
38.6k
Forks
4k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from httpie/cli

All issues in httpie/cli

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.