Mercurial > hgrepos > Python > libs > ConfigMix
diff configmix/compat.py @ 487:d7f6f2afcee2
Instead of using u(str(v)) use specialized functions for PY2 and PY3
| author | Franz Glasner <f.glasner@feldmann-mg.com> |
|---|---|
| date | Fri, 17 Dec 2021 16:06:49 +0100 |
| parents | b96f49c9c76b |
| children | f454889e41fa |
line wrap: on
line diff
--- a/configmix/compat.py Fri Dec 17 15:56:53 2021 +0100 +++ b/configmix/compat.py Fri Dec 17 16:06:49 2021 +0100 @@ -16,7 +16,8 @@ "u", "u2fs", "uchr", - "n"] + "n", + "str_and_u"] import sys @@ -78,6 +79,12 @@ else: return s.encode(encoding) + def str_and_u(v): + if isinstance(v, unicode): # noqa: F821 + return v + else: + return u(str(v)) + else: def text_to_native_os_str(s, encoding=None): @@ -116,3 +123,10 @@ return s else: return s.decode(encoding) + + def str_and_u(v): + """Convert the value in `v` of any type to a native string and then + to text (Unicode) + + """ + return str(v)
