Skip to content

Latest commit

 

History

History
37 lines (26 loc) · 1.8 KB

extensions.md

File metadata and controls

37 lines (26 loc) · 1.8 KB

Extended Types

For convenience, additional types are defined to handle common scenarios.

Numbers

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:

Text

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: