Remove the unicode compatibility function

This commit is contained in:
Dave Halter
2020-07-24 01:51:30 +02:00
parent 21f782dc34
commit a1829ecc7f
4 changed files with 7 additions and 18 deletions

View File

@@ -4,10 +4,4 @@ created. Clearly there is huge need to use conforming syntax.
"""
import platform
# unicode function
try:
unicode = unicode
except NameError:
unicode = str
is_pypy = platform.python_implementation() == 'PyPy'

View File

@@ -48,7 +48,6 @@ try:
except ImportError:
from collections import Mapping
from parso._compatibility import unicode
from parso.tree import Node, BaseNode, Leaf, ErrorNode, ErrorLeaf, \
search_ancestor
from parso.python.prefix import split_prefix
@@ -306,7 +305,7 @@ class _StringComparisonMixin(object):
Make comparisons with strings easy.
Improves the readability of the parser.
"""
if isinstance(other, (str, unicode)):
if isinstance(other, str):
return self.value == other
return self is other

View File

@@ -1,4 +1,3 @@
import sys
from abc import abstractmethod, abstractproperty
from parso.utils import split_lines
@@ -313,7 +312,6 @@ class BaseNode(NodeOrLeaf):
except AttributeError:
return element
index = int((lower + upper) / 2)
element = self.children[index]
if position <= element.end_pos:

View File

@@ -4,8 +4,6 @@ import sys
from ast import literal_eval
from functools import total_ordering
from parso._compatibility import unicode
# The following is a list in Python that are line breaks in str.splitlines, but
# not in Python. In Python only \r (Carriage Return, 0xD) and \n (Line Feed,
# 0xA) are allowed to split lines.
@@ -97,24 +95,24 @@ def python_bytes_to_unicode(source, encoding='utf-8', errors='strict'):
# the default if nothing else has been set -> PEP 263
return encoding
if isinstance(source, unicode):
if isinstance(source, str):
# only cast str/bytes
return source
encoding = detect_encoding()
if not isinstance(encoding, unicode):
encoding = unicode(encoding, 'utf-8', 'replace')
if not isinstance(encoding, str):
encoding = str(encoding, 'utf-8', 'replace')
try:
# Cast to unicode
return unicode(source, encoding, errors)
return str(source, encoding, errors)
except LookupError:
if errors == 'replace':
# This is a weird case that can happen if the given encoding is not
# a valid encoding. This usually shouldn't happen with provided
# encodings, but can happen if somebody uses encoding declarations
# like `# coding: foo-8`.
return unicode(source, 'utf-8', errors)
return str(source, 'utf-8', errors)
raise
@@ -179,7 +177,7 @@ def parse_version_string(version=None):
"""
if version is None:
version = '%s.%s' % sys.version_info[:2]
if not isinstance(version, (unicode, str)):
if not isinstance(version, str):
raise TypeError('version must be a string like "3.8"')
return _parse_version(version)