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

Ethan Furman ethan at stoneleaf.us
Thu Apr 7 16:28:57 EDT 2016


On 04/07/2016 01:21 PM, Paul Moore wrote:
> On 7 April 2016 at 20:43, Ethan Furman 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).

True, but:

- Python 3.3 isn't going to check for __os_path__

- Python 3.3 isn't going to check for an ABC

In other words, Python 3.3* simply isn't going to work with pathlib, so 
I continue to be confused with why Brett brought it up.

--
~Ethan~


* In case there's any confusion: by "not work" I mean the stdlib is not 
going to correctly interpret a pathlib.Path in 3.3 and earlier.


More information about the Python-ideas mailing list