[Python-ideas] PEP 428 - object-oriented filesystem paths
Antoine Pitrou
solipsis at pitrou.net
Sat Oct 13 10:22:04 CEST 2012
On Sat, 13 Oct 2012 17:41:29 +1000
Nick Coghlan <ncoghlan at gmail.com> wrote:
>
> Something else I've been thinking about is that it still feels wrong
> to me to be making the Windows vs Posix behavioural decision at the
> class level. It really feels more like a "decimal.Context" style API
> would be more appropriate, where there was a PathContext that
> determined how various operations on paths behaved. The default
> context would then be determined by the current OS, but you could
> write:
>
> with pathlib.PosixContext:
> # "\" is not a directory separator
> # "/" is used in representations
> # Comparison is case sensitive
> # expanduser() uses posix rules
>
> with pathlib.WindowsContext:
> # "\" and "/" are directory separators
> # "\" is used in representations
> # Comparison is case insensitive
:-/
You could make an argument that the Path classes could have their
behaviour tweaked with such a context system, but I really think
explicit classes for different path flavours are much better design
than some thread-local context hackery. Personally, I consider
thread-local contexts to be an anti-pattern.
(also, the idea that a POSIX path becomes a Windows path based on which
"with" statement it's used inside sounds scary)
Regards
Antoine.
--
Software development and contracting: http://pro.pitrou.net
More information about the Python-ideas
mailing list