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 — Use f-strings instead of str.format within importlib · Issue #82874 · python/cpython

Use f-strings instead of str.format within importlib #82874

New issue
Copy link
New issue
Copy link
Closed
Closed
Use f-strings instead of str.format within importlib#82874
Copy link
Assignees
gpshead
Labels
3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-importlib

Description

@gpshead
gpshead
opened on Nov 5, 2019
Issue body actions
BPO 38693
Nosy @gpshead, @jaraco, @ericvsmith, @serhiy-storchaka, @csabella, @miss-islington, @tirkarthi, @FFY00
PRs
  • bpo-38693: Use f-strings instead of str.format() within importlib #17058
  • bpo-38693: importlib.metadata f-strings #26383
  • [3.10] bpo-38693: importlib.metadata f-strings (GH-26383) #26386
  • bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). #26387
  • [3.10] bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387) #26389
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gpshead'
    closed_at = None
    created_at = <Date 2019-11-05.06:20:17.309>
    labels = ['3.11', 'performance']
    title = 'Use f-strings instead of str.format within importlib'
    updated_at = <Date 2021-05-26.21:09:35.360>
    user = 'https://github.com/gpshead'

    bugs.python.org fields:

    activity = <Date 2021-05-26.21:09:35.360>
    actor = 'jaraco'
    assignee = 'gregory.p.smith'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2019-11-05.06:20:17.309>
    creator = 'gregory.p.smith'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 38693
    keywords = ['patch']
    message_count = 9.0
    messages = ['356005', '369672', '378998', '393617', '393629', '394453', '394454', '394460', '394463']
    nosy_count = 8.0
    nosy_names = ['gregory.p.smith', 'jaraco', 'eric.smith', 'serhiy.storchaka', 'cheryl.sabella', 'miss-islington', 'xtreak', 'FFY00']
    pr_nums = ['17058', '26383', '26386', '26387', '26389']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'performance'
    url = 'https://bugs.python.org/issue38693'
    versions = ['Python 3.11']

    Activity

    1. gpshead commented on Nov 5, 2019

      @gpshead
      gpshead
      on Nov 5, 2019
      MemberAuthor
      More actions

      importlib is full of str.format calls, modernizing it to use f-strings is a slight performance win and much more readable.

    2. gpshead
      added
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      on Nov 5, 2019
    3. gpshead
      self-assigned this
      on Nov 5, 2019
    4. gpshead
      added
      performancePerformance or resource usagePerformance or resource usage
      on Nov 5, 2019
    5. csabella commented on May 23, 2020

      @csabella
      csabella
      on May 23, 2020
      Contributor
      More actions

      Did you want this one to land in 3.9?

    6. gpshead
      added
      3.10 (EOL)end of lifeend of life
      and removed
      3.8 (EOL)end of lifeend of life
      3.9 (EOL)end of lifeend of life
      on Oct 19, 2020
    7. gpshead commented on Oct 19, 2020

      @gpshead
      gpshead
      on Oct 19, 2020
      MemberAuthor
      More actions

      Status: Waiting until after the importlib.metadata and importlib.resources backports drop support for both Python 2.7 and 3.5 as keeping them in sync would be a pain for maintainers (per jaraco on our sprint importlib-any chat today)

    8. FFY00 commented on May 13, 2021

      @FFY00
      FFY00
      on May 13, 2021
      Member
      More actions

      Both importlib_metadata and importlib_resources have dropped support for Python 2.7 and 3.5, this should now be unblocked.

    9. serhiy-storchaka commented on May 14, 2021

      @serhiy-storchaka
      serhiy-storchaka
      on May 14, 2021
      Member
      More actions

      I just have merged a change which makes many C-style formatting as fast as f-strings (bpo-28307) and am working on supporting more format codes (%d, %x, %f, etc). Using C-style formatting can be a good option if you want performance and backward compatibility. It was faster than str.format() even without that optimization.

    10. serhiy-storchaka
      added
      3.11only security fixesonly security fixes
      and removed
      3.10 (EOL)end of lifeend of life
      on May 14, 2021
    11. miss-islington commented on May 26, 2021

      @miss-islington
      miss-islington
      on May 26, 2021
      Contributor
      More actions

      New changeset e6c815d by Jason R. Coombs in branch 'main':
      bpo-38693: importlib.metadata f-strings (GH-26383)
      e6c815d

    12. miss-islington commented on May 26, 2021

      @miss-islington
      miss-islington
      on May 26, 2021
      Contributor
      More actions

      New changeset 78a8428 by Miss Islington (bot) in branch '3.10':
      bpo-38693: importlib.metadata f-strings (GH-26383)
      78a8428

    13. miss-islington commented on May 26, 2021

      @miss-islington
      miss-islington
      on May 26, 2021
      Contributor
      More actions

      New changeset f6fbdb9 by Jason R. Coombs in branch 'main':
      bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387)
      f6fbdb9

    14. jaraco commented on May 26, 2021

      @jaraco
      jaraco
      on May 26, 2021
      Member
      More actions

      New changeset 97b4576 by Miss Islington (bot) in branch '3.10':
      bpo-38693: Prefer f-strings in importlib.resources (importlib_resources 5.0.6). (GH-26387) (bpo-26389)
      97b4576

    15. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    16. serhiy-storchaka
      added
      topic-importlib
      on May 21, 2022
    17. iritkatriel
      added
      3.12only security fixesonly security fixes
      and removed
      3.11only security fixesonly security fixes
      on Aug 26, 2022
    18. gpshead commented on Oct 6, 2022

      @gpshead
      gpshead
      on Oct 6, 2022
      MemberAuthor
      More actions

      #17058 did this for Lib/importlib/_bootstrap.py

    19. gpshead commented on Oct 6, 2022

      @gpshead
      gpshead
      on Oct 6, 2022
      MemberAuthor
      More actions

      remaining things to consider (not all need to be converted):

      $ grep -R '[.]format' Lib/importlib/
      Lib/importlib/_bootstrap_external.py:    path_tmp = '{}.{}'.format(path, id(path))
      Lib/importlib/_bootstrap_external.py:            raise ValueError('{!r} is not alphanumeric'.format(optimization))
      Lib/importlib/_bootstrap_external.py:        almost_filename = '{}.{}{}'.format(almost_filename, _OPT, optimization)
      Lib/importlib/_bootstrap_external.py:        _warnings.warn(msg.format(portions[0]), ImportWarning)
      Lib/importlib/_bootstrap_external.py:        raise ImportError('Non-code object in {!r}'.format(bytecode_path),
      Lib/importlib/_bootstrap_external.py:        key = registry_key.format(fullname=fullname,
      Lib/importlib/_bootstrap_external.py:                              'returns None'.format(module.__name__))
      Lib/importlib/_bootstrap_external.py:        return '_NamespacePath({!r})'.format(self._path)
      Lib/importlib/_bootstrap_external.py:                    new_name = '{}.{}'.format(name, suffix.lower())
      Lib/importlib/_bootstrap_external.py:        return 'FileFinder({!r})'.format(self.path)
      Lib/importlib/metadata/__init__.py:        return text and map('"{}"'.format, text.splitlines())
      Lib/importlib/resources/_adapters.py:        "Invalid mode value '{}', only 'r' and 'rb' are supported".format(mode)
      Lib/importlib/_bootstrap.py:        print(message.format(*args), file=sys.stderr)
      Lib/importlib/__init__.py:            raise ValueError('{}.__loader__ is None'.format(name))
      Lib/importlib/__init__.py:        raise ValueError('{}.__loader__ is not set'.format(name)) from None
      Lib/importlib/__init__.py:            raise ImportError('spec for {} missing loader'.format(name),
      Lib/importlib/__init__.py:            raise TypeError(msg.format(name))
      Lib/importlib/__init__.py:        raise ImportError(msg.format(name), name=name)
      Lib/importlib/__init__.py:                raise ImportError(msg.format(parent_name),
      Lib/importlib/util.py:            raise ValueError('{}.__spec__ is not set'.format(name)) from None
      Lib/importlib/util.py:                raise ValueError('{}.__spec__ is None'.format(name))
      Lib/importlib/util.py:            raise ValueError('{}.__spec__ is not set'.format(name)) from None
      Lib/importlib/util.py:                raise ValueError('{}.__spec__ is None'.format(name))
      
    20. gpshead
      added a commit that references this issue on Oct 7, 2022

      gh-82874: Convert remaining importlib format uses to f-str. (#98005)

      27369ef
    21. gpshead
      closed this as completedon Oct 7, 2022
    22. carljm
      added a commit that references this issue on Oct 8, 2022

      Merge branch 'main' into typewatch

      0de5aff
    23. mpage
      added a commit that references this issue on Oct 11, 2022

      pythongh-82874: Convert remaining importlib format uses to f-str. (py…

      c729f2d
    24. jaraco
      added a commit that references this issue on Feb 17, 2023

      pythongh-82874: Convert remaining importlib format uses to f-str. (py…

      222aaed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    • @gpshead
      gpshead

    Labels

    3.12only security fixesonly security fixesperformancePerformance or resource usagePerformance or resource usagetopic-importlib

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      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.