Re: [Python-Dev] proposed os.fspath() change

2016年6月15日 12:27:27 -0700

On Wed, Jun 15, 2016 at 10:15 PM, Brett Cannon <[email protected]> wrote:
>
>
> On 2016年6月15日 at 12:12 Koos Zevenhoven <[email protected]> wrote:
>>
>> >> if isinstance(filename, os.PathLike):
>>
>> By the way, regarding the line of code above, is there a convention
>> regarding whether implementing some protocol/interface requires
>> registering with (or inheriting from) the appropriate ABC for it to
>> work in all situations. IOW, in this case, is it sufficient to
>> implement __fspath__ to make your type pathlike? Is there a conscious
>> trend towards requiring the ABC?
>
>
> ABCs like os.PathLike can override __subclasshook__ so that registration
> isn't required (see
> https://hg.python.org/cpython/file/default/Lib/os.py#l1136). So registration
> is definitely good to do to be explicit that you're trying to meet an ABC,
> but it isn't strictly required.
Ok I suppose that's fine, so I propose we update the ABC part in the
PEP with __subclasshook__.
And the other question could be turned into whether to make str and
bytes also PathLike in __subclasshook__.
-- Koos
-- 
+ Koos Zevenhoven + http://twitter.com/k7hoven +
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to