def inline(self, field, context):
# type: (fields.Field, JitContext) -> Optional[str]
"""Generates a template for inlining string serialization.
For example, generates "float(value) if value is not None else None"
to serialize a float. If `field.as_string` is `True` the result will
be coerced to a string if not None.
"""
if (is_overridden(field._validated, fields.Number._validated) or
is_overridden(field._serialize, fields.Number._serialize)):
return None
result = field.num_type.__name__ + '({0})'
if field.as_string and context.is_serializing:
result = 'str({0})'.format(result)
if field.allow_none is True:
# Only emit the Null checking code if nulls are allowed. If they
# aren't allowed casting `None` to an integer will throw and the
# slow path will take over.
result += ' if {0} is not None else None'
return result