Repository navigation
pathlib's Path("NUL:").resolve() throws an error on windows #85708
Description
Activity
I'm looking for the equivalent windows functionality to the posix `/dev/null` file, and I discovered `NUL:`
This snippet works on a windows OS, proving that it is indeed a writable file:
Path('NUL:').write_text('abcd')However,
Path('NUL:').resolve()Throws an exceptionOSError: [WinError 87] The parameter is incorrect: 'NUL:'Is this the expected behaviour? I.E. I should wrap the call to
resolve()in atry...except?If I catch all
OSErrortypes, how can I determine if it's a legitimate error or not?E.G. Full console output:
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> from pathlib import Path >>> Path('NUL:') WindowsPath('NUL:') >>> Path('NUL:').write_text('abcd') 4 >>> Path('NUL:').resolve() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Program Files\Python37\lib\pathlib.py", line 1134, in resolve s = self._flavour.resolve(self, strict=strict) File "C:\Program Files\Python37\lib\pathlib.py", line 192, in resolve s = self._ext_to_normal(_getfinalpathname(s)) OSError: [WinError 87] The parameter is incorrect: 'NUL:'- added3.7 (EOL)end of lifeend of lifetype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Aug 13, 2020 The trailing colon is unnecessary, and likely to cause more issues, but the same thing occurs for Path('NUL').resolve()
This is probably best handled as bpo-37517, where you'll find more background on the error messages.
But I believe that p.resolve(strict=True) should not raise when open(p) will succeed, and p.resolve(strict=False) should not raise when open(p) will succeed or raise a *NotFoundError subclass of OSError.
- added3.8 (EOL)end of lifeend of life3.9 (EOL)end of lifeend of life3.10 (EOL)end of lifeend of lifeand removed3.7 (EOL)end of lifeend of life
on Aug 13, 2020 - addedstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on Nov 23, 2023 This was fixed in 3.10 by GH-25264.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsDone
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields: