Skip to content

Commit 6e9b745

Browse files
committed
Extract a _draw_ordinary_datetime helper
1 parent a3c852c commit 6e9b745

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

  • hypothesis/src/hypothesis/strategies/_internal

‎hypothesis/src/hypothesis/strategies/_internal/datetime.py‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -484,16 +484,19 @@ def do_draw(self, data):
484484
)
485485
if self.tricky_possible and data.draw_boolean(_TRICKY_P):
486486
result = self.draw_tricky_datetime(data, tz)
487-
elif self.aware:
488-
result = self.draw_aware_datetime(data, tz)
489487
else:
490-
result = self.draw_naive_datetime(data, tz)
488+
result = self._draw_ordinary_datetime(data, tz)
491489

492490
# If we happened to end up with a disallowed imaginary time, reject it.
493491
if (not self.allow_imaginary) and datetime_does_not_exist(result):
494492
data.mark_invalid(f"{result} does not exist (usually a DST transition)")
495493
return result
496494

495+
def _draw_ordinary_datetime(self, data, tz):
496+
if self.aware:
497+
return self.draw_aware_datetime(data, tz)
498+
return self.draw_naive_datetime(data, tz)
499+
497500
def draw_tricky_datetime(self, data, tz):
498501
"""Draw a tricky datetime using the interesting instants."""
499502
try:
@@ -510,9 +513,8 @@ def draw_tricky_datetime(self, data, tz):
510513
else:
511514
window = (self.min_value, self.max_value)
512515
if not instants:
513-
if self.aware:
514-
return self.draw_aware_datetime(data, tz)
515-
return self.draw_naive_datetime(data, tz)
516+
# if it turns out nothing is tricky, fall back to a normal draw
517+
return self._draw_ordinary_datetime(data, tz)
516518
instant = instants[
517519
data.draw_integer(0, len(instants) - 1, shrink_towards=nearest)
518520
]

0 commit comments

Comments
 (0)