[Python-Dev] file system path protocol PEP
Sven R. Kunze
srkunze at mail.de
Sat May 14 05:36:08 EDT 2016
More information about the Python-Dev mailing list
Sat May 14 05:36:08 EDT 2016
- Previous message (by thread): [Python-Dev] file system path protocol PEP
- Next message (by thread): [Python-Dev] file system path protocol PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 13.05.2016 18:43, Chris Angelico wrote: > https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_Check > > https://docs.python.org/3/c-api/unicode.html#c.PyUnicode_CheckExact Thanks for pointing me at this. I searched via github and found usages only: https://github.com/python/cpython/search?utf8=%E2%9C%93&q=PyUnicode_Check > "Check" accepts subclasses; "CheckExact" doesn't (it's like "type(x) > is str"). The question is, which one SHOULD be being done? What should > this do: > > class TmpPath(str): > def __fspath__(self): > return "/tmp/"+self > x = TmpPath("foo/bar") > open(x, "w") > > Does that respect __fspath__, or respect the fact that it's a string? Fine example. Thinking naively, I would say, when somebody made an effort to write __fspath__, it should be respected. Maybe, that's just me. Not sure if that can be a source of errors, when somebody adds str as baseclass later because the team needs str functionality. At least I would expect __fspath__ to still work . Best, Sven
- Previous message (by thread): [Python-Dev] file system path protocol PEP
- Next message (by thread): [Python-Dev] file system path protocol PEP
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list