From e73562c6f14d1d71a9fea174d58465e1b13f68af Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Tue, 9 Mar 2021 09:02:50 +0100 Subject: remove python 2 specific code add future deprecation warning to old style functions --- scalarstring.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'scalarstring.py') 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) -- cgit v1.2.1