[New-bugs-announce] [issue33646] os.fspath() bypasses __fspath__ for str subclasses

Joseph Martinot-Lagarde report at bugs.python.org
Fri May 25 06:00:01 EDT 2018


New submission from Joseph Martinot-Lagarde <contrebasse at gmail.com>:

os.fspath() returns its argument if it is a str. That means that it bypasses __fspath__ for str subclasses.

This is the case for the library path.py for example.

This is a corner case that was discovered while trying to fix https://github.com/matplotlib/matplotlib/issues/11306

Minimal example:

```
import os

class MyPath(str):
    def __fspath__(self):
        print("Returns a pure string")
        return str(self)

os.fspath(MyPath())  # Prints nothing
```

----------
components: Library (Lib)
messages: 317666
nosy: contrebasse
priority: normal
severity: normal
status: open
title: os.fspath() bypasses __fspath__ for str subclasses
type: behavior
versions: Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33646>
_______________________________________


More information about the New-bugs-announce mailing list