You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Feature Request] [stdlib] Add Path.devnull() for the platform's null device #7618
I have read the roadmap and priorities and I believe this request falls within the 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.
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?
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 ?
Activity
Tharun-Kumar-McW commentedon Nov 15, 2026
Hi @NathanSWard,
I'd like to work on this, unless someone's already on it. My plan is to add
Path.devnull()as a@staticmethodnext toPath.home(), returning/dev/nullon Linux and macOS, with a test intest_pathlib.mojoand a changelog entry. Does that approach sound good?One question: every target we support today has
/dev/null, sodevnull()would never raise there. Should it keepraises IOErrorfor future platforms (and if so, whichIOErrorKindfits, since there's no "unsupported" kind), or would you rather it not raise and use acomptime asserton unknown platforms, likeProcess.rundoes?I'll wait for your go-ahead before opening a PR.
NathanSWard commentedon Nov 15, 2026
@Tharun-Kumar-McW sounds great! I would leave it as raising an
IOErrorand also do acomptime 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.
Tharun-Kumar-McW commentedon Nov 15, 2026
Thanks @NathanSWard! Makes sense, I'll keep
raises IOErrorso a future platform can look up the null device at runtime, and add acomptime assert CompilationTarget.is_linux() or CompilationTarget.is_macos()for now. PR coming soon.Could you please assign this issue ?
[stdlib] Cap file reads and writes only on macOS
[stdlib] Cap file reads and writes only on macOS
[External] [stdlib] Add Path.devnull() (#112138)