Skip to content

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

Description

@truongsontung

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

Activity

  1. truongsontung commented on Jul 14, 2026

    @truongsontung
    Author

    Follow-up: confirmed the bug — os.system is a built-in function object, so os.system == 'nt' is always False and the Windows short-circuit never fires (the function instead relies on a swallowed FileNotFoundError to return False by accident).

    The intended guard should be a real platform check, e.g.:

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

    (sys.platform == 'win32' is the most robust Windows detector; os.name == 'nt' works too.)

    Happy to open a PR that (1) swaps the guard for sys.platform == 'win32' and (2) adds a regression test asserting is_available() == (sys.platform == 'win32') so this can't silently regress again. Just let me know if you'd like me to send it.

  2. added 4 commits that reference this issue on Jul 21, 2026
    0e9a6a4
    dee5f76
    7bfeeb0
    f84b3ce
  3. added a commit that references this issue on Jul 25, 2026
    1fc01be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions