Skip to content

Commit d70279f

Browse files
committed
Cosmetic change
1 parent d1a6cd8 commit d70279f

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

Lib/uuid.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ class UUID:
108108
109109
fields a tuple of the six integer fields of the UUID,
110110
which are also available as six individual attributes
111-
and two derived attributes:
111+
and two derived attributes. The time_* attributes are
112+
only relevant to version 1, while the others are only
113+
relevant to versions 1 and 6:
112114
113115
time_low the first 32 bits of the UUID
114116
time_mid the next 16 bits of the UUID
@@ -322,17 +324,17 @@ def clock_seq_low(self):
322324

323325
@property
324326
def time(self):
325-
field_1 = self.int >> 96
326-
field_3_no_ver = (self.int >> 64) & 0x0fff
327-
328327
if self.version == 6:
329-
# In version 6, the first field contains the 32 MSBs
330-
# and the field after the version contains the 12 LSBs.
331-
return field_1 << 28 | (self.time_mid << 12) | field_3_no_ver
328+
# time_hi (32) | time_mid (16) | ver (4) | time_lo (12) | ... (64)
329+
time_hi, time_lo = self.int >> 96, (self.int >> 64) & 0x0fff
330+
return time_hi << 28 | (self.time_mid << 12) | time_lo
332331
else:
333-
# In version 1, the first field contains the 32 LSBs
334-
# and the field after the version contains the 12 MSBs.
335-
return field_3_no_ver << 48 | (self.time_mid << 32) | field_1
332+
# time_low (32) | time_mid (16) | ver (4) | time_hi (12) | ... (64)
333+
#
334+
# For compatibility purposes, we do not warn or raise when the
335+
# version is not 1 (timestamp is irrelevant to other versions).
336+
time_hi, time_lo = (self.int >> 64) & 0x0fff, self.int >> 96
337+
return time_hi << 48 | (self.time_mid << 32) | time_lo
336338

337339
@property
338340
def clock_seq(self):

0 commit comments

Comments
 (0)