pathlib (was: Defining a path protocol)

(1) I think the "built-in" should instead be a module-level function in the pathlib. If you aren't already expecting pathlib paths, then you're just expecting strings to work anyhow, and a builtin isn't likely to be helpful. (2) I prefer that the function be explicit about the fact that it is downcasting the representation to a string. e.g., pathlib.path_as_string(my_path) But if the final result is ospath or fspath or ... I won't fight too hard, particularly since the output may be a bytestring rather than a str. -jJ

On 8 April 2016 at 00:25, Jim J. Jewett <jimjjewett@gmail.com> wrote:
(1) I think the "built-in" should instead be a module-level function in the pathlib. If you aren't already expecting pathlib paths, then you're just expecting strings to work anyhow, and a builtin isn't likely to be helpful.
Concrete data in relation to "Why not put the helper function in pathlib?": >>> import sys >>> orig_modules = set(sys.modules) >>> "os" in orig_modules True >>> import pathlib >>> extra_dependencies = set(sys.modules) - orig_modules >>> print(sorted(extra_dependencies)) ['_collections', '_functools', '_heapq', '_operator', '_sre', 'collections', 'contextlib', 'copyreg', 'fnmatch', 'functools', 'heapq', 'itertools', 'keyword', 'ntpath', 'operator', 'pathlib', 're', 'reprlib', 'sre_compile', 'sre_constants', 'sre_parse', 'urllib', 'urllib.parse', 'weakref'] We want to be able to readily use the protocol helper in builtin modules like os and low level Python modules like os.path, which means we want it to be much lower down in the import hierarchy than pathlib. Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

Nick Coghlan wrote:
We want to be able to readily use the protocol helper in builtin modules like os and low level Python modules like os.path, which means we want it to be much lower down in the import hierarchy than pathlib.
Also, it's more general than that. It works on any object that wants to behave as a path, not just pathlib ones, so it should be in a neutral place. -- Greg
participants (3)
-
Greg Ewing
-
Jim J. Jewett
-
Nick Coghlan