[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: It should be emphasized that it may happen on a **file operation**... So at least be something like: "On some platforms, it may also be raised if a file operation involves an attempt to open or traverse a non-directory file as if it were a directory." -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: @Andrei Kulakov: That statement is mainly for illustration that such behavior may vary across platforms. I use a rather vague statement as I'm not totally sure it applies if (and only if) running on POSIX. A more accurate statement is welcome as long as it's proven true. -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: @Andrei Kulakov: I was commenting on the previous version. The revised version (f2ae30b0de3c4ba1f16fc2a430cf22b447c062ed) seems ok to me. Another question: would it be better if we add "on some platforms" for the part that the error may raise on a file operation? -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: > I've put up a PR that expands the docs for NotADirectoryError here: > https://github.com/python/cpython/pull/27471/files Thank you. Wouldn't it be more clear if an example is provided? Like: (e.g. `/path/to` does not exist when running `open('/path/to/file')`) -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: > Really? It's not obvious that finding a file would involve directory > operations? Not in some senses, and that's possibly why Windows does not raise NotADirectoryError in such case. I agree that it's a platform-specific implementation detail. However, there are lots of platform-specific implementation details written in documentation elsewhere already, especially OS related modules such as os and os.path. I don't think mentioning platform-specific implementation details for subclasses of OSError would be any less reasonable than that. Adding such notice for NotADirectoryError helps people who want a EAFP style code for nonexistent file by preventing them getting trapped writing a cross-platform code. -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: I don't think a general developer would expect that open('/path/to/file/somename.txt') implies a directory operation, and it also doesn't on Windows. I suggest that a further notice be added to NotADirectoryError, such as: Raised when a directory operation (such as os.listdir()) is requested on something which is not a directory. Corresponds to errno ENOTDIR. In some filesystem such as POSIX, NotADirectoryError (ENOTDIR) is raised when attempting to open a path whose ancestor is not a directory. -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file in a fake directory
Danny Lin added the comment: By writing "except FileNotFoundError:", the intention is to catch an error when the file being opened is not found, and don't catch an error for other cases, such as an existing file without adequate permission. Writing "except OSError:" catches just too much cases including unwanted ones. As they are not equivalent, you cannot say that the latter is the "correct" way for the former. And you totally omitted the argument for the inadequate documentation for NotADirectoryError. It says NotADirectoryError is raises when a DIRECTORY operation is requested, and does not cover the case of opening a file. -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue37529] Mimetype module duplicates
Danny Lin added the comment: It doesn't seem so... In Python 3.8.5 this code is still seen in mimetypes.py (line 492-504): '.bmp': 'image/bmp', '.gif': 'image/gif', '.ief': 'image/ief', '.jpg': 'image/jpeg', '.jpe': 'image/jpeg', '.jpeg' : 'image/jpeg', '.png': 'image/png', '.svg': 'image/svg+xml', '.tiff' : 'image/tiff', '.tif': 'image/tiff', '.ico': 'image/vnd.microsoft.icon', '.ras': 'image/x-cmu-raster', '.bmp': 'image/x-ms-bmp', -- nosy: +danny87105 ___ Python tracker <https://bugs.python.org/issue37529> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file under a fake directory
Danny Lin added the comment: I'm not so familiar about the spec. If such behavior is confirmed due to implementation difference across OSes, and it's also not desirable to change the mapping of the OS error to Python exception, we can simplify left it as-is. However, this behavior difference can potentially cause cross-platform compatibility. For example, the code: try: open('/path/to/file/somename.txt') except FileNotFoundError: """do something""" would work on Windows but break on Linux (or POSIX?). The current (3.8) description for exception NotADirectoryError is: Raised when a directory operation (such as os.listdir()) is requested on something which is not a directory. Corresponds to errno ENOTDIR. According to this, a user probably won't expect to receive a NotADirectoryError for open('/path/to/file/somename.txt'), as this doesn't seem like a directory operation at all, unless he is expert enough to know about the implication of errno ENOTDIR. I think a note should at least be added to the documentation if we are not going to change the behavior. -- ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41738] MIME type for *.zip becomes application/x-zip-compressed on Windows
New submission from Danny Lin : On Windows, command "python -m mimetypes foo.zip" outputs "type: application/x-zip-compressed encoding: None", while it's "type: application/zip encoding: None" on Linux. According to the mimetype.py in CPython source code, the MIME type for '.zip' is 'application/zip'. It seems to be overwritten somewhere on Windows. -- components: Windows messages: 376508 nosy: danny87105, paul.moore, steve.dower, tim.golden, zach.ware priority: normal severity: normal status: open title: MIME type for *.zip becomes application/x-zip-compressed on Windows type: behavior versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue41738> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue41737] Improper NotADirectoryError when opening a file under a fake directory
New submission from Danny Lin : On Linux (tested on Ubuntu 16.04), if "/path/to/file" is an existing file, the code: open('/path/to/file/somename.txt') raises NotADirectoryError: [Errno 20] Not a directory: '/path/to/file/somename.txt' On Windows, similar code: open(r'C:\path\to\file\somename.txt') raises FileNotFoundError: [Errno 2] No such file or directory: 'C:\\path\\chrome\\to\\file\\somename.txt' I think the behavior on Linux is not correct. The user probably cares about the existence of the file to be opened, rather than whether its ancestor directories are valid. OTOH, if NotADirectoryError should be raised, it should mention '/path/to/file' rather then '/path/to/file/somename.txt'. But what if '/path/to' or '/path' is actually a file? Should it be '/path/to' or '/path' instead for the same reason? -- messages: 376505 nosy: danny87105 priority: normal severity: normal status: open title: Improper NotADirectoryError when opening a file under a fake directory type: behavior versions: Python 3.8 ___ Python tracker <https://bugs.python.org/issue41737> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com