summaryrefslogtreecommitdiff
path: root/scalarstring.py
diff options
context:
space:
mode:
authorAnthon van der Neut <anthon@mnt.org>2021-03-09 09:02:50 +0100
committerAnthon van der Neut <anthon@mnt.org>2021-03-09 09:02:50 +0100
commite73562c6f14d1d71a9fea174d58465e1b13f68af (patch)
tree309851cca7d411b31c27753555871d493282c7f0 /scalarstring.py
parent96839d9f64f4698bdc519cbfbd48d51178460714 (diff)
downloadruamel.yaml-e73562c6f14d1d71a9fea174d58465e1b13f68af.tar.gz
remove python 2 specific code
add future deprecation warning to old style functions
Diffstat (limited to 'scalarstring.py')
-rw-r--r--scalarstring.py16
1 files changed, 6 insertions, 10 deletions
diff --git a/scalarstring.py b/scalarstring.py
index f164639..f5fb6a2 100644
--- a/scalarstring.py
+++ b/scalarstring.py
@@ -1,8 +1,5 @@
# coding: utf-8
-from __future__ import print_function, absolute_import, division, unicode_literals
-
-from ruamel.yaml.compat import text_type
from ruamel.yaml.anchor import Anchor
if False: # MYPY
@@ -21,20 +18,20 @@ __all__ = [
]
-class ScalarString(text_type):
+class ScalarString(str):
__slots__ = Anchor.attrib
def __new__(cls, *args, **kw):
# type: (Any, Any) -> Any
anchor = kw.pop('anchor', None) # type: ignore
- ret_val = text_type.__new__(cls, *args, **kw) # type: ignore
+ ret_val = str.__new__(cls, *args, **kw) # type: ignore
if anchor is not None:
ret_val.yaml_set_anchor(anchor, always_dump=True)
return ret_val
def replace(self, old, new, maxreplace=-1):
# type: (Any, Any, int) -> Any
- return type(self)((text_type.replace(self, old, new, maxreplace)))
+ return type(self)((str.replace(self, old, new, maxreplace)))
@property
def anchor(self):
@@ -129,8 +126,7 @@ def walk_tree(base, map=None):
map[':'] = SingleQuotedScalarString
walk_tree(data, map=map)
"""
- from ruamel.yaml.compat import string_types
- from ruamel.yaml.compat import MutableMapping, MutableSequence # type: ignore
+ from collections.abc import MutableMapping, MutableSequence # type: ignore
if map is None:
map = {'\n': preserve_literal}
@@ -138,7 +134,7 @@ def walk_tree(base, map=None):
if isinstance(base, MutableMapping):
for k in base:
v = base[k] # type: Text
- if isinstance(v, string_types):
+ if isinstance(v, str):
for ch in map:
if ch in v:
base[k] = map[ch](v)
@@ -147,7 +143,7 @@ def walk_tree(base, map=None):
walk_tree(v, map=map)
elif isinstance(base, MutableSequence):
for idx, elem in enumerate(base):
- if isinstance(elem, string_types):
+ if isinstance(elem, str):
for ch in map:
if ch in elem: # type: ignore
base[idx] = map[ch](elem)