add python3 compatibility#28
Conversation
|
@truebit hope you have time to review this PR :) |
|
Hi, @heni |
|
Ok, I have written all necessary methods from six explicitely |
| else: | ||
| return cmp(x, y) | ||
| def file_dir_order(x): | ||
| return ('.' in x, x) |
There was a problem hiding this comment.
this new compare method does not act as what I did before. It will put all dirs and files in alphabet order.
What I did before was putting dirs before files, and they both in alphbet order in their type. Doing a diff between the results would be more clear.
I will revert this change.
There was a problem hiding this comment.
You are wrong, the next code snippet
python -c "file_dir_order = (lambda x: ('.' in x, x)); print('\n'.join(name for name in sorted(['dir1', 'last_dir', 'file.m', 'a.h'], key=file_dir_order)))"
will print:
dir1 last_dir a.h file.m
(all dirs before files)
There was a problem hiding this comment.
The fact is that sorted function in python3 doesn't accept cmp attribute and the challenge is emulate old sorting behavior only with key extracting function
There was a problem hiding this comment.
Your code snippet is correct. But the difference really happened in python 2.7 and python 3.5
So the problem is in python 3 string sort method modification in line 272.
There was a problem hiding this comment.
Can you give me large list (>=20) of strings and wished output order for them?
Having this list I can write method that sort them in one perfect way for python2.7 and python3.5.
| if self.main_group_hex not in last_two[0]: | ||
| lines.sort(key=lambda file_str: children_pbx_key_ptn.search(file_str).group(), | ||
| cmp=file_dir_cmp) | ||
| lines.sort(key=lambda file_str: (children_pbx_key_ptn.search(file_str).group(), file_dir_order)) |
There was a problem hiding this comment.
Yep, I know that python3 removed cmp parameter in sort. But I think your lambda seems not correct. Though I am not very familiar with cmp and key in sort method
But the result could tell the difference. You could run your version and master on the same project file, you would see differences in the sorting dirs and files.
|
Traceback (most recent call last): I got this error with python3. |
|
@riveryan What the command arguments did you use? |
|
@riveryan I just uploaded new pip version to pypi including this pr. You can update xunique using command: |
No description provided.