MCPcopy
hub / github.com/django/django / to_python

Method to_python

django/forms/fields.py:579–596  ·  view source on GitHub ↗
(self, value)

Source from the content-addressed store, hash-verified

577 return value
578
579 def to_python(self, value):
580 if value in self.empty_values:
581 return None
582 if isinstance(value, datetime.timedelta):
583 return value
584 try:
585 value = parse_duration(str(value))
586 except OverflowError:
587 raise ValidationError(
588 self.error_messages["overflow"].format(
589 min_days=datetime.timedelta.min.days,
590 max_days=datetime.timedelta.max.days,
591 ),
592 code="overflow",
593 )
594 if value is None:
595 raise ValidationError(self.error_messages["invalid"], code="invalid")
596 return value
597
598
599class RegexField(CharField):

Callers

nothing calls this directly

Calls 3

parse_durationFunction · 0.90
ValidationErrorClass · 0.90
formatMethod · 0.45

Tested by

no test coverage detected