Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pathlib's Path("NUL:").resolve() throws an error on windows #85708

Closed
phillmac mannequin opened this issue Aug 13, 2020 · 3 comments
Closed

pathlib's Path("NUL:").resolve() throws an error on windows #85708

phillmac mannequin opened this issue Aug 13, 2020 · 3 comments
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes OS-windows stdlib Python modules in the Lib dir topic-pathlib type-bug An unexpected behavior, bug, or error

Comments

@phillmac
Copy link
Mannequin

phillmac mannequin commented Aug 13, 2020

BPO 41536
Nosy @pfmoore, @tjguk, @zware, @eryksun, @zooba, @phillmac

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:

assignee = None
closed_at = None
created_at = <Date 2020-08-13.02:29:57.872>
labels = ['3.10', 'type-bug', '3.8', '3.9', 'OS-windows']
title = 'pathlib\'s Path("NUL:").resolve() throws an error on windows'
updated_at = <Date 2020-08-13.20:24:51.975>
user = 'https://github.com/phillmac'

bugs.python.org fields:

activity = <Date 2020-08-13.20:24:51.975>
actor = 'steve.dower'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['Windows']
creation = <Date 2020-08-13.02:29:57.872>
creator = 'phillmac'
dependencies = []
files = []
hgrepos = []
issue_num = 41536
keywords = []
message_count = 2.0
messages = ['375289', '375342']
nosy_count = 6.0
nosy_names = ['paul.moore', 'tim.golden', 'zach.ware', 'eryksun', 'steve.dower', 'phillmac']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue41536'
versions = ['Python 3.8', 'Python 3.9', 'Python 3.10']

@phillmac
Copy link
Mannequin Author

phillmac mannequin commented Aug 13, 2020

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 exception OSError: [WinError 87] The parameter is incorrect: 'NUL:'

Is this the expected behaviour? I.E. I should wrap the call to resolve() in a try...except?

If I catch all OSError types, 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:'

@phillmac phillmac mannequin added 3.7 (EOL) end of life OS-windows type-bug An unexpected behavior, bug, or error labels Aug 13, 2020
@zooba
Copy link
Member

zooba commented 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.

@zooba zooba added 3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes and removed 3.7 (EOL) end of life labels Aug 13, 2020
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 23, 2023
@barneygale
Copy link
Contributor

This was fixed in 3.10 by GH-25264.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 (EOL) end of life 3.9 only security fixes 3.10 only security fixes OS-windows stdlib Python modules in the Lib dir topic-pathlib type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants