diff options
author | Anthon van der Neut <anthon@mnt.org> | 2017-08-05 12:28:35 +0200 |
---|---|---|
committer | Anthon van der Neut <anthon@mnt.org> | 2017-08-05 12:28:35 +0200 |
commit | ea1cd43722d6e8cc6ddf9190b09a5ad818313be6 (patch) | |
tree | 8e486f2180f2b67b21b067203ee53a202089b875 /error.py | |
parent | c4dda520edb15b010c9134d6f81b26abbb1c8a90 (diff) | |
download | ruamel.yaml-ea1cd43722d6e8cc6ddf9190b09a5ad818313be6.tar.gz |
warn on incorrect YAML 1.1 floats
Diffstat (limited to 'error.py')
-rw-r--r-- | error.py | 26 |
1 files changed, 26 insertions, 0 deletions
@@ -193,6 +193,32 @@ In most other cases you should consider using 'safe_load(stream)'""" warnings.simplefilter('once', UnsafeLoaderWarning) +class MantissaNoDotYAML1_1Warning(YAMLWarning): + def __init__(self, node, flt_str): + self.node = node + self.flt = flt_str + + def __str__(self): + line = self.node.start_mark.line + col = self.node.start_mark.column + return """ +In YAML 1.1 floating point values should have a dot ('.') in their mantissa. +See the Floating-Point Language-Independent Type for YAML™ Version 1.1 specification +( http://yaml.org/type/float.html ). This dot is not required for JSON nor for YAML 1.2 + +Correct your float: "{}" on line: {}, column: {} + +or alternatively include the following in your code: + + import warnings + warnings.simplefilter('ignore', ruamel.yaml.error.MantissaNoDotYAML1_1Warning) + +""".format(self.flt, line, col) + + +warnings.simplefilter('once', MantissaNoDotYAML1_1Warning) + + class YAMLFutureWarning(Warning): pass |