On 14 May 2016 at 19:36, Sven R. Kunze <srku...@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 | ncogh...@gmail.com | Brisbane, Australia _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com