Skip to content
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

:flat 1 crashes ranger #2812

Closed
vejkse opened this issue Mar 24, 2023 · 6 comments · Fixed by #2818
Closed

:flat 1 crashes ranger #2812

vejkse opened this issue Mar 24, 2023 · 6 comments · Fixed by #2818

Comments

@vejkse
Copy link

vejkse commented Mar 24, 2023

Runtime Environment

  • Operating system and version: Linux 6.2.7
  • Terminal emulator and version: Alacritty
  • Python version: 3.10.10
  • Ranger version/commit: 8875ad2 (the problem arises already with 46660c2)
  • Locale: mixture of en_US.UTF-8, en_DK.UTF-8, POSIX

Current Behavior

When executing :flat 1 in any directory, ranger crashes. Tested with ranger --clean.

Expected Behavior

Not crashing and displaying all files up to depth 1.

Possible Solutions

Rollback to a previous version. I have commit f8b304f available and it works fine.

Traceback

ranger version: ranger-master
Python version: 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201]
Locale: en_US.UTF-8
Current file: '/home'

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/ranger/core/main.py", line 204, in main
    fm.loop()
  File "/usr/lib/python3.10/site-packages/ranger/core/fm.py", line 417, in loop
    ui.redraw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/ui.py", line 343, in redraw
    self.draw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/ui.py", line 370, in draw
    DisplayableContainer.draw(self)
  File "/usr/lib/python3.10/site-packages/ranger/gui/displayable.py", line 268, in draw
    displayable.draw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/widgets/view_miller.py", line 98, in draw
    directory.load_content_if_outdated()
  File "/usr/lib/python3.10/site-packages/ranger/container/directory.py", line 678, in load_content_if_outdated
    real_mtime = mtimelevel(self.path, self.flat)
  File "/usr/lib/python3.10/site-packages/ranger/container/directory.py", line 89, in mtimelevel
    for dirpath, dirnames, _ in walklevel(path, level):
  File "/usr/lib/python3.10/site-packages/ranger/container/directory.py", line 78, in walklevel
    assert os.path.isdir(some_dir)
AssertionError
@vejkse
Copy link
Author

vejkse commented Mar 24, 2023

I sometimes have a slightly different error:

Traceback (most recent call last):
  File "/usr/lib/python3.10/site-packages/ranger/core/main.py", line 204, in main
    fm.loop()
  File "/usr/lib/python3.10/site-packages/ranger/core/fm.py", line 417, in loop
    ui.redraw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/ui.py", line 343, in redraw
    self.draw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/ui.py", line 370, in draw
    DisplayableContainer.draw(self)
  File "/usr/lib/python3.10/site-packages/ranger/gui/displayable.py", line 268, in draw
    displayable.draw()
  File "/usr/lib/python3.10/site-packages/ranger/gui/widgets/view_miller.py", line 98, in draw
    directory.load_content_if_outdated()
  File "/usr/lib/python3.10/site-packages/ranger/container/directory.py", line 678, in load_content_if_outdated
    real_mtime = mtimelevel(self.path, self.flat)
  File "/usr/lib/python3.10/site-packages/ranger/container/directory.py", line 92, in mtimelevel
    mtime = max(mtime, [-1] + [os.stat(d).st_mtime for d in dirlist])
TypeError: '>' not supported between instances of 'list' and 'float'

Combined with the fact that the only recent change in the file directory.py is this one line: 49fc14d, it seems clear that the removed max was necessary.

I changed back by hand this line and everything works fine.

@vejkse
Copy link
Author

vejkse commented Mar 24, 2023

I think I know where this comes from: I just ran pylint directory.py and one of the messages is

directory.py:92:16: W3301: Do not use nested call of 'max'; it's possible to do 'max(mtime, [-1] + [os.stat(d).st_mtime for d in dirlist])' instead (nested-min-max)

Clearly it shouldn’t suggest that. There is in fact a recent pylint bug about that: pylint-dev/pylint#8168.

@vejkse
Copy link
Author

vejkse commented Mar 24, 2023

So, after looking at the pylint bug, which is not solved for this specific case, rather than reverting the commit 49fc14d, it suffices to add a * in the line:

mtime = max(mtime, *[-1] + [os.stat(d).st_mtime for d in dirlist])

(or perhaps simply to move mtime, inside the square bracket).

@toonn
Copy link
Member

toonn commented Mar 30, 2023

Thank you for bringing this to our attention!

I agree we should just append mtime instead of the -1.

toonn added a commit to toonn/ranger that referenced this issue Mar 30, 2023
Pylint flagged a nested max call as redundant but it was a false
positive. However, the nested max call materialized a generator as a
list and prepended `-1` because the function errors on an empty
argument. Instead of nesting a max call we can drop the nesting and
prepend the current value instead of passing it as a separate argument.

Fixes ranger#2812

Co-authored-by: vejkse <[email protected]>
@toonn
Copy link
Member

toonn commented Mar 30, 2023

I've opened a PR, tried to add you as a co-author on the commit with a GitHub no-reply email. Could you confirm I used the correct committer email address for you, or whether you'd prefer not to be listed in the first place?

@vejkse
Copy link
Author

vejkse commented Apr 1, 2023

Sorry, I just saw this, having been busy these last few days. I think I’d just prefer not to be listed.

@toonn toonn closed this as completed in 454c2d1 Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants