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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4