[Python-ideas] Dunder method to make object str-like

Paul Moore p.f.moore at gmail.com
Thu Apr 7 16:21:28 EDT 2016


On 7 April 2016 at 20:43, Ethan Furman <ethan at stoneleaf.us> wrote:
> On 04/07/2016 12:17 PM, Brett Cannon wrote:
>
>> How do you make Python 3.3 code work with this when the ABC will simply
>> not be available to you unless you're running Python 3.4.3, 3.5.2, or
>> 3.6.0 (under the assumption that the ABC is put in pathlib and
>> backported thanks to its provisional status)? The ternary operator
>> one-liner is backwards-compatible while the ABC is only
>> forward-compatible.
>
>
> __os_path__ (or whatever it's called) also won't be available on those
> earlier versions -- so I'm not seeing that the ABC route as any worse.
>
> Am I missing something?

You can check for __os_path__ even if it doesn't exist (hasattr takes
the name as a string), but you can't check for the ABC if it doesn't
exist (isinstance takes the actual ABC as the argument).

Paul


More information about the Python-ideas mailing list