[issue9820] Windows : os.listdir(b'.') doesn't raise an errorfor unencodablefilenames

Martin v. Löwis report at bugs.python.org
Sun Sep 12 23:30:20 CEST 2010


Martin v. Löwis <martin at v.loewis.de> added the comment:

> About Windows, os.listdir(str) never fails, but my question is about 
> os.listdir(bytes). Should os.listdir(bytes) returns invalid filenames (encoded 
> with "mbcs+replace", filenames not usable to open, rename or delete the file) or 
> just ignore them?

I see nothing wrong with returning incorrect file names.

> "it only wants to open some of the files" is the typical reason for which I 
> hate Python2 and its implicit conversion between bytes and characters: it 
> works in most cases, but it fails "sometimes". The problem is to define (and 
> explain) "sometimes".

Notice that this doesn't change with the patch. It will *still* work
sometimes, and fail sometimes. In fact, for most users and most
applications, it will never fail - *even with your patch applied*.

> Ignore unencodable filenames solution is compatible with the "traverse into 
> subdirectories" case. And it does also keep backward compatibility (except 
> that unencodable files are hidden, which is a least problem I think).

I fail to see why removing incorrect file names from the result list is
any better than keeping them. The result list will be incorrect either way.

In one case (files skipped), the user will not see the file in the
selection dialog, even though he knows its there and explorer shows it
just fine. So he thinks there must be a bug.

In the other case, it displays a non-sensical file name. Again, the user
thinks there is a bug - plus if you click on the file, you get some
error message (hopefully, the application will catch the exception -
the directory may also have changed in-between, so a missing file
error must be recovered from).

So it's a user-visible bug in either case, but if the incorrect file
name is included, it's slightly more obvious that something is wrong.

----------
title: Windows : os.listdir(b'.') doesn't raise an errorfor	unencodablefilenames -> Windows : os.listdir(b'.') doesn't raise an	errorfor unencodablefilenames

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9820>
_______________________________________


More information about the Python-bugs-list mailing list