MCPcopy Index your code
hub / github.com/django/django / to_python

Method to_python

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

Source from the content-addressed store, hash-verified

1355 super().__init__(**kwargs)
1356
1357 def to_python(self, value):
1358 if self.disabled:
1359 return value
1360 if value in self.empty_values:
1361 return None
1362 elif isinstance(value, (list, dict, int, float, JSONString)):
1363 return value
1364 try:
1365 converted = json.loads(value, cls=self.decoder)
1366 except json.JSONDecodeError:
1367 raise ValidationError(
1368 self.error_messages["invalid"],
1369 code="invalid",
1370 params={"value": value},
1371 )
1372 if isinstance(converted, str):
1373 return JSONString(converted)
1374 else:
1375 return converted
1376
1377 def bound_data(self, data, initial):
1378 if self.disabled:

Callers 1

has_changedMethod · 0.95

Calls 3

ValidationErrorClass · 0.90
JSONStringClass · 0.85
loadsMethod · 0.45

Tested by

no test coverage detected