You could rewrite this function as followed (just as proposal):
```python
if not isinstance(path, unicode):
    filesystem_encoding = sys.getfilesystemencoding() or sys.getdefaultencoding()
    path = path.decode(filesystem_encoding)
return path