[Python-Dev] file system path protocol PEP (original) (raw)
Sven R. Kunze srkunze at mail.de
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.PyUnicodeCheck
https://docs.python.org/3/c-api/unicode.html#c.PyUnicodeCheckExact
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 ]