New submission from tegavu <tegavu8...@sogetthis.com>:

Wrong behavior in pathlib.PureWindowsPath - sorting does not use natural sort.

Everything below was written based on W7x64 & Python 3.8.1 
(tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit (AMD64)] on 
win32.

The documentation 
(https://docs.python.org/3/library/pathlib.html#general-properties) states: 
"Paths of a same flavour are comparable and orderable."

This can be done like this:

from pathlib import *
print( PureWindowsPath('C:\\1') < PureWindowsPath('C:\\a') )

This returns True. This is expected because 1 is sorted before a on Windows.

This sorting also works well for harder cases where other sorting functions 
fail: !1 should be before 1 and !a should be before a.

But it fails with natural sorting:

from pathlib import *
print( PureWindowsPath('C:\\15') < PureWindowsPath('C:\\100') )

This returns False.

This is a bug in my opinion, since PureWindowsPath should sort like 
Windows(Explorer) would sort. 

Right now PureWindowsPath does probably something like NTFS sorting, but NTFS 
is not Windows and from a function called 'WindowsPath' I expect a path that 
would be given in Windows Explorer.

In case a simple `dir` on Windows sorts by NTFS names (I am not sure!), 
PureWindowsPath also fails, since (for example) "[" < "a" should be False.

See this image for comparison:
https://i.imgur.com/GjBhWsS.png

Here is a string that can be used directly as a list to check sorting:

test_list = ['15', '100', '11111', '!', '#', '$', '%', '&', "'", '(', ')', '+', 
'+11111', '+aaaaa', ',', '-', ';', '=', '@', '[', ']', '^', '_', '`', 'aaaaa', 
'foo0', 'foo_0', '{', '}', '~', '§', '°', '´', 'µ', '€']

----------
messages: 361315
nosy: tegavu
priority: normal
severity: normal
status: open
title: Pathlib PureWindowsPath sorting incorrect (is not natural sort)
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue39544>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to