-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
detect Path objects in argument iterable and auto-use ns.P #16
Comments
I am very reluctant to have I am wondering, is there a reason that you aren't sure the type of the incoming data? If you know that you want to sort paths, you can just always add the Would the following be acceptable alternatives? >>> # Convert to string if the input is a Path object.
>>> natsorted(mylist, key=lambda x: str(x) if isinstance(x, pathlib.Path) else x, alg=ns.P) or >>> # Just convert everything to strings.
>>> natsorted(mylist, key=lambda x: str(x), alg=ns.P) I might be open to adding an option that will do the checking and turning on of the path algorithm, but the user has to request this explicitly. |
Oh, of course I know the type of the data and key argument works. At the end it's all about practicality vs. speed. What about using the first key argument (convert only Path instances to str) when ns.P is on? |
I will look into this. |
I have fixed this in a recent commit. I will release as an incremental update (version 3.5.2) in a few days. |
It'd be nice if natsort autodetects whether its arguments are all Path objects (from the new stdlib's
pathlib
), converted them to strs, and turned onns.P
automatically (and possiblyns.IC
on Windows too). I don't have a strong opinion of what to do if some arguments are Paths and others are not (I guess this should fail with TypeError since they are not technically comparable).The text was updated successfully, but these errors were encountered: