Skip to content

Conversation

@tonghuaroot
Copy link

@tonghuaroot tonghuaroot commented Jan 18, 2026

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.

@bedevere-app
Copy link

bedevere-app bot commented Jan 18, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jan 18, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@tonghuaroot tonghuaroot changed the title Modernize Lib/uuid.py: use f-strings gh-143986: Modernize Lib/uuid.py: use f-strings Jan 18, 2026
@bedevere-app
Copy link

bedevere-app bot commented Jan 18, 2026

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant