click icon indicating copy to clipboard operation
click copied to clipboard

use the path_type to perform the other click.Path checks

Open hoshimura opened this issue 1 month ago • 4 comments

click.Path exposes a path_type but does currently not use it for path sanity checks such as exists, file_okay, dir_okay etc. If path_type is for instance a cloudpathlib.AnyPath and the cli user points to a S3 those checks will always go wrong since they expect path_type to handle only local paths. Issue #2661 addressed similar thoughts but when the path_type itself is pathlib compliant, I would hope that click.Path would honor the users wish to supply their own path_type.

hoshimura avatar Oct 20 '26 13:10 hoshimura

I think the key distinction here is that path_type shouldn't just control the returned value — it should also be the object used for the checks when one is provided.

Right now convert() runs os.stat() / os.access() on the original value and only calls coerce_path_result() at the end. That makes path_type=cloudpathlib.AnyPath ineffective for exists, file_okay, dir_okay, etc. because those checks are still against the local filesystem.

It seems reasonable to coerce the value first when path_type is set, then use the resulting object's path semantics for the checks, while keeping the current os.* behavior for the default local-path case.

That would also make path_type behave more like an actual path abstraction rather than only a return-type conversion.

faizansaiyed123 avatar Oct 20 '26 16:10 faizansaiyed123

The Path param type is intended for local paths only. Maybe we should make that more clear. The path_type arg is purely for migrating to use Path instead of str. We couldn't change the default without breaking, but everyone wanted the new Path type instead of the old os.path strings. But there's a deep assumption that we're working with local paths, so it's fine to use os.path internally. Changing that would mean adding a different code path based on what the type was, which is a lot of complexity.

In retrospect, I would never have added path_type, I would have made a new Pathlib param type. Similarly, you should probably create a CloudPath param type to do exactly what you need.

davidism avatar Oct 20 '26 16:10 davidism

@faizansaiyed123 please read https://palletsprojects.com/contributing/llm-ai

davidism avatar Oct 20 '26 16:10 davidism

@davidism thank you for your answer. I guess it means you disapprove this feature request? If that is so, I am sorry, for click is a really great lib and I am sure my request would add value to it. If you approve, I am gladly willing to help with an implementation

hoshimura avatar Oct 21 '26 06:10 hoshimura