Skip to content

Bug fix: Make sure arg of max is not an empty sequence - #11

Closed
MaxGyver83 wants to merge 1 commit into
Glitchy-Tozier:mainfrom
MaxGyver83:main
Closed

Bug fix: Make sure arg of max is not an empty sequence#11
MaxGyver83 wants to merge 1 commit into
Glitchy-Tozier:mainfrom
MaxGyver83:main

Conversation

@MaxGyver83

Copy link
Copy Markdown
Contributor

When I comment out the English and French BigramsConfigs and set the weight for German to 100% and reduce the NR_OF_BEST_LAYOUTS to 50, the optimizer crashes with this error message:

Traceback (most recent call last):
  File "/media/home/max/repos/8vim_keyboard_layout_calculator/main.py", line 1106, in <module>
    main()
  File "/media/home/max/repos/8vim_keyboard_layout_calculator/main.py", line 271, in main
    showDataInTerminal(finalLayoutList, finalScoresList, customLayouts)
  File "/media/home/max/repos/8vim_keyboard_layout_calculator/main.py", line 927, in showDataInTerminal
    printLayoutData(layout, placing=idx+1)
  File "/media/home/max/repos/8vim_keyboard_layout_calculator/main.py", line 1057, in printLayoutData
    maxVisNameLen = max(len(i.name) for i in configSpecificData if i.name != 'All')
ValueError: arg is an empty sequence

Changes in this pull request:

  • Prevent this error by checking if the sequence passed to max() is empty.
  • Fix a typo.

@Glitchy-Tozier

Glitchy-Tozier commented Apr 22, 2023

Copy link
Copy Markdown
Owner

Good catch, seems like I always used multiple BigramConfigs. Must've been difficult to fix the code in that convoluted area!

I'd like to propose a different fix, however: Removing the if-check in line 1017.

    if len(BIGRAMS_CONFIGS) > 1: # <- Remove this check
        for config in BIGRAMS_CONFIGS: # <- Always run the loop
            originalWeight = config.weight
            fullWeightConfig = config.fullWeightClone()

            configSpecificData.append(ConfigSpecificResults(
                config.name,
                originalWeight,
                getBigrams(layout, (fullWeightConfig, )),
            ))

This way the issue gets fixed and the output seems a bit more transparent (the user still gets shown which language was used).

@MaxGyver83

Copy link
Copy Markdown
Contributor Author

Your fix looks good. Probably the right way to go. I have tested it and it didn't crash. Then I'll just close my pull request. Thanks for looking deeper into it!

@MaxGyver83 MaxGyver83 closed this Apr 22, 2023
@Glitchy-Tozier

Copy link
Copy Markdown
Owner

Okay, I'll push the fix later today, then!

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 this pull request may close these issues.

2 participants