For convenience, additional types are defined to handle common scenarios.
The Number
converter should be used for values that can be both integers or floats, but should not be coerced into either type during serialization.
from typing import Optional
from datafiles.converters import Number
Type Annotation | Python Value | YAML Content |
---|---|---|
foobar: Number |
foobar = 42 |
foobar: 42 |
foobar: Number |
foobar = 1.23 |
foobar: 1.23 |
foobar: Number |
foobar = None |
foobar: 0.0 |
foobar: Optional[Number] |
foobar = None |
foobar: |
The Text
converter should be used for strings that contain lines of text, which are optimally serialized across multiple lines in a file.
from typing import Optional
from datafiles.converters import Text
Type Annotation | Python Value | YAML Content |
---|---|---|
foobar: Text |
foobar = "Hello, world!" |
foobar: Hello, world! |
foobar: Text |
foobar = "First\nSecond\n" |
`foobar: |
foobar: Text |
foobar = None |
foobar: '' |
foobar: Optional[Text] |
foobar = None |
foobar: |