Skip to content

Modernize Lib/uuid.py: use f-strings #143986

@tonghuaroot

Description

@tonghuaroot

Feature or enhancement

Proposal:

Description

Lib/uuid.py currently uses older string formatting methods (% operator and .format()) in a few places. This task resolves to modernizing these to use f-strings (PEP 498) for improved readability and consistency with modern Python codebases.

Proposed Changes

  • Replace '%s(%r)' % (self.__class__.__name__, str(self)) with f'{self.__class__.__name__}({str(self)!r})' in UUID.__repr__.
  • Replace os.fsencode('(%s)' % ip_addr) with os.fsencode(f'({ip_addr})') in _arp_getnode.
  • Replace assert False, '_random_getnode() returned invalid value: {}'.format(_node) with f-string version in getnode.

Verification

  • Run python Lib/test/test_uuid.py to ensure all tests pass.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-refactorCode refactoring (with no changes in behavior)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions