Skip to content

Commit 1056131

Browse files
committed
Modernize Lib/uuid.py: use f-strings
This change replaces instances of legacy string formatting ('%' operator and .format() method) with f-strings in Lib/uuid.py. This improves readability and aligns with modern Python coding standards. Specific changes: - UUID.__repr__: '%s(%r)' -> f-string - _arp_getnode: '(%s)' -> f-string - getnode assertion: .format() -> f-string
1 parent 7e28ae5 commit 1056131

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Lib/uuid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ def __int__(self):
323323
return self.int
324324

325325
def __repr__(self):
326-
return '%s(%r)' % (self.__class__.__name__, str(self))
326+
return f'{self.__class__.__name__}({str(self)!r})'
327327

328328
def __setattr__(self, name, value):
329329
raise TypeError('UUID objects are immutable')
@@ -611,7 +611,7 @@ def _arp_getnode():
611611
return mac
612612

613613
# This works on Linux, FreeBSD and NetBSD
614-
mac = _find_mac_near_keyword('arp', '-an', [os.fsencode('(%s)' % ip_addr)],
614+
mac = _find_mac_near_keyword('arp', '-an', [os.fsencode(f'({ip_addr})')],
615615
lambda i: i+2)
616616
# Return None instead of 0.
617617
if mac:
@@ -718,7 +718,7 @@ def getnode():
718718
continue
719719
if (_node is not None) and (0 <= _node < (1 << 48)):
720720
return _node
721-
assert False, '_random_getnode() returned invalid value: {}'.format(_node)
721+
assert False, f'_random_getnode() returned invalid value: {_node}'
722722

723723

724724
_last_timestamp = None

0 commit comments

Comments
 (0)