Skip to content

Apply pyupgrade and refurb suggestions #352

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

DimitriPapadopoulos
Copy link
Contributor

No description provided.

src/header.py Outdated
@@ -1,4 +1,3 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whitespace is significant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what I suspected, but it's not clear why. Is additional code added in front of it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these files are compiled into the single-file versioneer.py file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alternative would be to add the extra line when compiling the versioneer.py file in setup.py. But then, why change something that works?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, but I still need to look into the files under test.

@DimitriPapadopoulos DimitriPapadopoulos force-pushed the pyupgrade branch 4 times, most recently from ac8e499 to 3ba033b Compare December 17, 2022 13:59
Copy link
Contributor

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All seems fine. Some small suggestions, but I'm okay to merge as-is.


print("set %s to '%s'" % (filename, versions["version"]))
print("set {} to '{}'".format(filename, versions["version"]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might as well use an f-string if we're here.

Suggested change
print("set {} to '{}'".format(filename, versions["version"]))
print(f"set {filename} to {versions['version']:r}")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then we're modifying functionality, by changing '%s' to {...} instead of '{...}', aren't we?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I suspect you meant !r instead of :r. It will call repr(), but then how is that helpful?

>>> i = 2
>>> 
>>> f"We print 'i' as '{i}'"
"We print 'i' as '2'"
>>> 
>>> f"We print 'i' as {i!r}"
"We print 'i' as 2"
>>> 

We might use triple quotes instead:

f"""set {filename} to '{versions["version"]}'"""

But then it gets unreadable.

@DimitriPapadopoulos
Copy link
Contributor Author

DimitriPapadopoulos commented Dec 18, 2022

I still need to fix these flake8 errors, don't I?

  git_version.py:335:89: E501 line too long (90 > 88 characters)
  versioneer.py:809:89: E501 line too long (90 > 88 characters)
  versioneer.py:1330:89: E501 line too long (90 > 88 characters)

I believe this flake8 line length limit is complete nonsense when applied to strings, especially f-strings with longer replacement fields.

See for example what the Linux kernel coding style has to say about it:

The limit on the length of lines is 80 columns and this is a strongly preferred limit.

[...] However, never break user-visible strings such as printk messages, because that breaks the ability to grep for them.

Use f-strings wherever possible.
* [FURB109]: Replace `in [x, y, z]` with `in (x, y, z)`
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy