GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-38693: Use f-strings instead of str.format() within importlib by gpshead · Pull Request #17058 · python/cpython

Conversation

@gpshead

@gpshead gpshead commented Nov 5, 2019 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

This is a small performance improvement, especially for one or two hot
places such as _handle_fromlist() that are called a lot and the
str.format() method was being used just to join two strings with a '.'.

Otherwise it is merely a readability improvement.

This could be backported to 3.8 as it does not change any logic.

I kept _ERR_MSG as an attribute in importlib._bootstrap and imp
as I wasn't sure if there were other things in the world that might
refer to those. They're private and could go away in 3.9 but should
not within 3.8 just in case.

https://bugs.python.org/issue38693

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gpshead added 2 commits November 4, 2019 22:15
@gpshead
Use of f-strings instead of .format() in importlib.
5ffb681
This is a small performance improvement, especially for one or two hot
places such as _handle_fromlist() that are called a lot and the
.format() method was being used just to join two strings with a dot.

Otherwise it is merely a readability improvement.

This could be backported to 3.8 as it changes no functionality.

I kept `_ERR_MSG` as an attribute in `importlib._bootstrap` and `imp`
as I wasn't sure if there were other things in the world that might
refer to those.  They're private and could go away in 3.9 but should
not within 3.8 just in case.
@gpshead
NEWS entry!
bcb2891
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Nov 5, 2019
@bedevere-bot bedevere-bot added the awaiting core review label Nov 5, 2019
@gpshead
gpshead requested a review from brettcannon November 5, 2019 06:24
@gpshead gpshead added the needs backport to 3.8 label Nov 5, 2019
@gpshead
undo the Lib/imp.py change.
592a529
It belongs with a later _ERR_MSG cleanup.
@gpshead gpshead removed the needs backport to 3.8 label Nov 5, 2019
ericvsmith
ericvsmith reviewed Nov 5, 2019
View reviewed changes

@ericvsmith ericvsmith left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I think this is generally a good idea, and all of the changes look correct.

However, I'm not sure I'd remove the use of _ERR_MSG, since it is used outside of this file. Either that, or remove it in Lib/imp.py, too (the only other place it's used).

I'm also not sure what value is added by _ERR_MSG_PREFIX. It doesn't seem to be used anywhere. I'd just roll it into _ERR_MSG, if it's being kept.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@brettcannon

brettcannon commented Nov 5, 2019

Copy link
Copy Markdown
Member

_ERR_MSG was actually created specifically because there have been numerous instances where that sentence has been formatted differently across the code base (with or without a period, capitalized or not, wording, etc.). I think _ERR_MSG_PREFIX was created because it was used from import.c.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

brettcannon
brettcannon requested changes Nov 5, 2019
View reviewed changes

@brettcannon brettcannon left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Need to decide what the ultimate fate of _ERR_MSG is.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added awaiting changes and removed awaiting core review labels Nov 5, 2019
@bedevere-bot

bedevere-bot commented Nov 5, 2019

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@csabella

csabella commented Jan 25, 2020

Copy link
Copy Markdown
Contributor

@gpshead, please take a look at the review comments. Thanks!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jaraco
jaraco approved these changes May 26, 2021
View reviewed changes
@bedevere-bot bedevere-bot added awaiting merge and removed awaiting changes labels May 26, 2021
@jaraco jaraco added needs backport to 3.9 labels May 26, 2021
@ambv

ambv commented May 17, 2022

Copy link
Copy Markdown
Contributor

This missed the boat for inclusion in Python 3.9 which accepts security fixes only as of today.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ambv ambv removed the needs backport to 3.9 label May 17, 2022
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.11 only security fixes label May 20, 2022
@gpshead gpshead mentioned this pull request May 21, 2022
Use f-strings instead of str.format within importlib #82874
Closed
@ezio-melotti ezio-melotti removed the CLA signed label Jul 13, 2022
@gpshead gpshead removed needs backport to 3.10 needs backport to 3.11 only security fixes labels Oct 6, 2022
gpshead added 2 commits October 6, 2022 14:25
@gpshead
Merge branch 'main' into minor-importlib-opts
3607bda
@gpshead
mis-edit fix
9cd4bf6
@gpshead

gpshead commented Oct 6, 2022

Copy link
Copy Markdown
Member Author

I'm not sure I'd remove the use of _ERR_MSG, since it is used outside of this file. Either that, or remove it in Lib/imp.py, too (the only other place it's used).

I left _ERR_MSG and _ERR_MSG_PREFIX in place as they could be used by others. The code now uses the latter within its own f-string.

PTAL

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@gpshead gpshead added sprint topic-importlib labels Oct 6, 2022
@gpshead gpshead self-assigned this Oct 6, 2022
ericvsmith
ericvsmith reviewed Oct 6, 2022
View reviewed changes

@ericvsmith ericvsmith left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Other than the tiny nit I mentioned, LGTM.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/importlib/_bootstrap.py Outdated
if module is None:
message = ('import of {} halted; '
'None in sys.modules'.format(name))
message = (f'import of {name} halted; None in sys.modules')

@ericvsmith ericvsmith Oct 6, 2022

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The parens here can be deleted; it looks like they were previously used for the multi-line string.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gpshead
who needs ()s?
31245ec
ericvsmith
ericvsmith approved these changes Oct 6, 2022
View reviewed changes
@gpshead
remove the extra space.
333cbc4
@gpshead
gpshead merged commit 683ab85 into python:main Oct 6, 2022
@bedevere-bot bedevere-bot removed the awaiting merge label Oct 6, 2022
@gpshead
gpshead deleted the minor-importlib-opts branch October 6, 2022 23:43
carljm added a commit to carljm/cpython that referenced this pull request Oct 8, 2022
@carljm
Merge branch 'main' into typewatch
29e38df
* main:
  bpo-35540 dataclasses.asdict now supports defaultdict fields (pythongh-32056)
  pythonGH-91052: Add C API for watching dictionaries (pythonGH-31787)
  bpo-38693: Use f-strings instead of str.format() within importlib (python#17058)
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
@gpshead @mpage
bpo-38693: Use f-strings instead of str.format() within importlib (py…
f8e002a
…thon#17058)

This is a small performance improvement, especially for one or two hot
places such as _handle_fromlist() that are called a lot and the
.format() method was being used just to join two strings with a dot.

Otherwise it is merely a readability improvement.

We keep `_ERR_MSG` and `_ERR_MSG_PREFIX` as those may be used elsewhere for canonical looking error messages.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@brettcannon brettcannon brettcannon requested changes
@jaraco jaraco jaraco approved these changes
@ericvsmith ericvsmith ericvsmith approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gpshead gpshead

Labels

sprint topic-importlib

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

10 participants

@gpshead @brettcannon @bedevere-bot @csabella @ambv @jaraco @ericvsmith @serhiy-storchaka @the-knights-who-say-ni @ezio-melotti
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.