summaryrefslogtreecommitdiff
path: root/scalarstring.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2017-03-21 17:18:18 +0100
committerAnthon van der Neut <anthon@mnt.org>2017-03-21 17:18:18 +0100
commit9ac44a0873d51d63150b0f1dc1d009b206577a29 (patch)
tree44fc2ecbdba2a6a63544097d7b9f63d8f87d5aae /scalarstring.py
parentc8568f99215aaa910953287f63a25459e3800dfc (diff)
downloadruamel.yaml-9ac44a0873d51d63150b0f1dc1d009b206577a29.tar.gz
update for mypy --strict, prepare de-inheritance (Loader/Dumper)0.14.0
Diffstat (limited to 'scalarstring.py')
-rw-r--r--scalarstring.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/scalarstring.py b/scalarstring.py
index c6e5734..da43bcf 100644
--- a/scalarstring.py
+++ b/scalarstring.py
@@ -3,6 +3,8 @@
from __future__ import absolute_import
from __future__ import print_function
+from typing import Text, Any, Dict, List # NOQA
+
from ruamel.yaml.compat import text_type
__all__ = ["ScalarString", "PreservedScalarString", "SingleQuotedScalarString",
@@ -13,13 +15,15 @@ class ScalarString(text_type):
__slots__ = ()
def __new__(cls, *args, **kw):
- return text_type.__new__(cls, *args, **kw)
+ # type: (Any, Any) -> Any
+ return text_type.__new__(cls, *args, **kw) # type: ignore
class PreservedScalarString(ScalarString):
__slots__ = ()
def __new__(cls, value):
+ # type: (Text) -> Any
return ScalarString.__new__(cls, value)
@@ -27,6 +31,7 @@ class SingleQuotedScalarString(ScalarString):
__slots__ = ()
def __new__(cls, value):
+ # type: (Text) -> Any
return ScalarString.__new__(cls, value)
@@ -34,14 +39,17 @@ class DoubleQuotedScalarString(ScalarString):
__slots__ = ()
def __new__(cls, value):
+ # type: (Text) -> Any
return ScalarString.__new__(cls, value)
def preserve_literal(s):
+ # type: (Text) -> Text
return PreservedScalarString(s.replace('\r\n', '\n').replace('\r', '\n'))
def walk_tree(base):
+ # type: (Any) -> None
"""
the routine here walks over a simple yaml tree (recursing in
dict values and list items) and converts strings that
@@ -51,15 +59,14 @@ def walk_tree(base):
if isinstance(base, dict):
for k in base:
- v = base[k]
+ v = base[k] # type: Text
if isinstance(v, string_types) and '\n' in v:
base[k] = preserve_literal(v)
else:
walk_tree(v)
elif isinstance(base, list):
for idx, elem in enumerate(base):
- if isinstance(elem, string_types) and '\n' in elem:
- print(elem)
- base[idx] = preserve_literal(elem)
+ if isinstance(elem, string_types) and '\n' in elem: # type: ignore
+ base[idx] = preserve_literal(elem) # type: ignore
else:
walk_tree(elem)