On 17 April 2016 at 18:03, Stephen J. Turnbull <stephen at xemacs.org> wrote: > Nick Coghlan writes: > > and instead throw exceptions in those cases. > > Then I don't understand the current design of fsdecode and fsencode. > Shouldn't they raise on str and bytes respectively, rather than > passing them through? In general, I would expect that something > that's explicitly intended to be polymorphic would be documented as > such, and the *caller* would be responsible for type-checking and > raising if it got the wrong thing. > I was initially surprised myself, but then realised it made sense for their intended use cases - if almost every usage looks like "obj if isinstance(obj, str) else os.fsdecode(obj)", then there ends up being a strong pragmatic case for pushing the pass-through down into the underlying function to reduce code duplication and rejecting str input in the cases where it isn't supported. By contrast, there are lots of places where "obj.decode()" gets called without a pass-through for objects that are already decoded. Cheers, Nick. -- Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160417/6953c682/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4