Skip to content

Fix warning about wrong usage of 'is' #8

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

Merged
merged 1 commit into from
Apr 17, 2023

Conversation

MaxGyver83
Copy link
Contributor

  1. Get rid of warning in script output:
./8vim_keyboard_layout_calculator/main.py:63: SyntaxWarning: "is" with a literal. Did you mean "=="?
  1. Simplify (l for l in zip(*sortedScoreIdxTuples[-nrOfBest:]))

  2. Fix some linter warnings.

@Glitchy-Tozier
Copy link
Owner

Hi and thank you for the PR! It seems to run fine, though I have a question to one specific change:
What is the purpose of adding the additional escape-backslashes in this section?

blueprint = """   \\  {27}         {28}  /
 {26}  \\  {19}       {20}  /  {29}
  {18}  \\  {11}     {12}  /  {21}
   {10}  \\  {3}   {4}  /  {13}
    {2}  \\ _____ /  {5}
        |     |
        |_____|
    {1}  /       \\  {6}
   {9}  /  {0}   {7}  \\  {14}
  {17}  /  {8}     {15}  \\  {22}
 {25}  /  {16}       {23}  \\  {30}
   /  {24}         {31}  \\ """

At first glance, the layout seems to show just fine without them.

@MaxGyver83
Copy link
Contributor Author

Hi and thank you for the PR! It seems to run fine, though I have a question to one specific change: What is the purpose of adding the additional escape-backslashes in this section?

blueprint = """   \\  {27}         {28}  /
 {26}  \\  {19}       {20}  /  {29}
  {18}  \\  {11}     {12}  /  {21}
   {10}  \\  {3}   {4}  /  {13}
    {2}  \\ _____ /  {5}
        |     |
        |_____|
    {1}  /       \\  {6}
   {9}  /  {0}   {7}  \\  {14}
  {17}  /  {8}     {15}  \\  {22}
 {25}  /  {16}       {23}  \\  {30}
   /  {24}         {31}  \\ """

At first glance, the layout seems to show just fine without them.

My linter (pycodestyle) complains about single backslashes:
image

Backslashes are used as escape characters in strings. If you want to use a backslash in a string, it needs to be escaped by a backslash itself.

In [1]: print("\\")
\

A backslash followed by a space is not a recognized escape sequence. As far as I understand, this works but it will be an error in future Python versions:

Changed in version 3.6: Unrecognized escape sequences produce a DeprecationWarning. In a future Python version they will be a SyntaxWarning and eventually a SyntaxError.

raw strings are an exception:

In [2]: print(r"\\")
\\

Here a backslash is a literal backslash.

More details here: 2.4.1. String and Bytes literals

@Glitchy-Tozier
Copy link
Owner

Got it, thanks again, merging the PR!


Off topic: Danke für deine Artikeln zu NEO, KOY etc.! Dank deiner Website habe ich vor ca. 2 Jahren beschlossen, zu KOY zu wechseln.

@Glitchy-Tozier Glitchy-Tozier merged commit 36b1a0c into Glitchy-Tozier:main Apr 17, 2023
@MaxGyver83
Copy link
Contributor Author

MaxGyver83 commented Apr 17, 2023

Thanks for merging! And thanks for this project!


Was für ein Zufall, dass du meine Website kennst! Ich freu mich natürlich, wenn jemand etwas damit anfangen kann!

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