mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-02 01:23:41 +08:00
Remove the unicode compatibility function
This commit is contained in:
@@ -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'
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user