On 14 May 2016 at 19:36, Sven R. Kunze <srkunze at mail.de> wrote: > Fine example. Thinking naively, I would say, when somebody made an effort to > write __fspath__, it should be respected. Maybe, that's just me. Over time, we've generally moved towards treating subclasses as if they were the base class where protocols are concerned, and encouraging the use of composition if people don't actually want that "is-a" behaviour. For example, compare the int protocol to the last major type protocol we added, index: >>> from operator import index >>> class MyInt(int): ... def __int__(self): ... return 42 ... def __index__(self): ... return 42 ... >>> x = MyInt(5) >>> x 5 >>> int(x) 42 >>> index(x) 5 In the case of retroactively added protocols like operator.index() and os.fspath(), where inheritance from the relevant builtin type was previously the only option, retaining that behaviour is also the only way to avoid a performance regression for those subclasses. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
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