[Python-Dev] os.path.join failure mode (original) (raw)
Nick Coghlan ncoghlan at gmail.com
Sat Feb 9 14:53:55 CET 2013
- Previous message: [Python-Dev] os.path.join failure mode
- Next message: [Python-Dev] os.path.join failure mode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Sat, Feb 9, 2013 at 11:31 PM, R. David Murray <rdmurray at bitdance.com> wrote:
The reason we avoid such type checks is that we prefer to operate via "duck typing", which means that if an object behaves like the expected input, it is accepted. Here, if we did an explicit type check for str, it would prevent join from working on an "act alike" object that had just enough str like methods to work correctly in os.join (for example, some specialized object that was among other things a filename proxy). Granted, this is pretty far-fetched for os.path.join, but the general principle applies :)
I occasionally ponder the possibility of a time where we have a string.Text ABC, and can stop hardcoding checks for isinstance(str) everywhere :P
(No, I'm not volunteering to write it. And if anyone does want to discuss it further, please start a new thread on python-ideas, as python-dev isn't the right venue)
Cheers, Nick.
-- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
- Previous message: [Python-Dev] os.path.join failure mode
- Next message: [Python-Dev] os.path.join failure mode
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]