Skip to content

[Feature Request] [stdlib] Add Path.devnull() for the platform's null device #7618

Closed

Description

@NathanSWard

Review Mojo's priorities

What is your request?

Add a Path.devnull() static method that returns the path to the platform's null device.

Code that needs a sink that discards writes, or a path argument whose output it ignores, hardcodes "/dev/null". That string works on every target Mojo supports today, but it puts a POSIX detail at every call site. A named API states the intent. It also gives one place to change if Mojo targets a platform with a different null device, such as Windows, which uses NUL.

Proposed API

struct Path:
    @staticmethod
    def devnull() raises IOError -> Path:
        ...

This follows Path.home(), the existing @staticmethod that returns a platform-dependent Path.

What is your motivation for this change?

N/A

Any other details?

No response

Activity

  1. added
    enhancement
    mojo
    needs: triage
    on Nov 15, 2026
  2. added
    Team: Mojo Libraries
    and removed
    needs: triage
    on Nov 15, 2026
  3. Tharun-Kumar-McW commented on Nov 15, 2026

    @Tharun-Kumar-McW
    Contributor

    Hi @NathanSWard,
    I'd like to work on this, unless someone's already on it. My plan is to add Path.devnull() as a @staticmethod next to Path.home(), returning /dev/null on Linux and macOS, with a test in test_pathlib.mojo and a changelog entry. Does that approach sound good?

    One question: every target we support today has /dev/null, so devnull() would never raise there. Should it keep raises IOError for future platforms (and if so, which IOErrorKind fits, since there's no "unsupported" kind), or would you rather it not raise and use a comptime assert on unknown platforms, like Process.run does?

    I'll wait for your go-ahead before opening a PR.

  4. NathanSWard commented on Nov 15, 2026

    @NathanSWard
    ContributorAuthor

    @Tharun-Kumar-McW sounds great! I would leave it as raising an IOError and also do a comptime assert platform.is_linux() or is_macos().

    This leaves the door open for us in case there are platforms where you have to query what the dev/nul path is which could potentially fail.

  5. Tharun-Kumar-McW commented on Nov 15, 2026

    @Tharun-Kumar-McW
    Contributor

    Thanks @NathanSWard! Makes sense, I'll keep raises IOError so a future platform can look up the null device at runtime, and add a comptime assert CompilationTarget.is_linux() or CompilationTarget.is_macos() for now. PR coming soon.
    Could you please assign this issue ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Team: Mojo Librariesbug_feature_triagedenhancementmojo

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions