pyfilesystem2: fs.listdir and UnicodeError

On my system for whatever reason I have a file whith wrong encoding in the / dir. Always if I want
for item in sorted(self.fs.listdir(_sel_dir)):

I have to encapsulate this by an exception for UnicodeDecodeError. I would prefer to not crash but just ignore this file.

(I am still looking on why that file anyway is there)

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 1
  • Comments: 29 (22 by maintainers)

Commits related to this issue

Most upvoted comments

listdir in the FS interface should definitely return unicode. It’s a guarantee made by the api which tries to isolate the developer from precisely this kind of real world nastiness. The boundary points would have to be internal where OSFS calls listdir and scandir

getsyspath could be an exception as it only needs to be a ‘path understood by the OS’. So I’d consider allowing that to return bytes, but I’m not sure what that would break off hand.

Maybe a getnativepath would be warranted? Would much rather add to the api than risk break anything.