mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-17 14:00:03 +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
|
import platform
|
||||||
|
|
||||||
# unicode function
|
|
||||||
try:
|
|
||||||
unicode = unicode
|
|
||||||
except NameError:
|
|
||||||
unicode = str
|
|
||||||
|
|
||||||
is_pypy = platform.python_implementation() == 'PyPy'
|
is_pypy = platform.python_implementation() == 'PyPy'
|
||||||
|
|||||||
@@ -48,7 +48,6 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from collections import Mapping
|
from collections import Mapping
|
||||||
|
|
||||||
from parso._compatibility import unicode
|
|
||||||
from parso.tree import Node, BaseNode, Leaf, ErrorNode, ErrorLeaf, \
|
from parso.tree import Node, BaseNode, Leaf, ErrorNode, ErrorLeaf, \
|
||||||
search_ancestor
|
search_ancestor
|
||||||
from parso.python.prefix import split_prefix
|
from parso.python.prefix import split_prefix
|
||||||
@@ -306,7 +305,7 @@ class _StringComparisonMixin(object):
|
|||||||
Make comparisons with strings easy.
|
Make comparisons with strings easy.
|
||||||
Improves the readability of the parser.
|
Improves the readability of the parser.
|
||||||
"""
|
"""
|
||||||
if isinstance(other, (str, unicode)):
|
if isinstance(other, str):
|
||||||
return self.value == other
|
return self.value == other
|
||||||
|
|
||||||
return self is other
|
return self is other
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import sys
|
|
||||||
from abc import abstractmethod, abstractproperty
|
from abc import abstractmethod, abstractproperty
|
||||||
|
|
||||||
from parso.utils import split_lines
|
from parso.utils import split_lines
|
||||||
@@ -313,7 +312,6 @@ class BaseNode(NodeOrLeaf):
|
|||||||
except AttributeError:
|
except AttributeError:
|
||||||
return element
|
return element
|
||||||
|
|
||||||
|
|
||||||
index = int((lower + upper) / 2)
|
index = int((lower + upper) / 2)
|
||||||
element = self.children[index]
|
element = self.children[index]
|
||||||
if position <= element.end_pos:
|
if position <= element.end_pos:
|
||||||
|
|||||||
+6
-8
@@ -4,8 +4,6 @@ import sys
|
|||||||
from ast import literal_eval
|
from ast import literal_eval
|
||||||
from functools import total_ordering
|
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
|
# 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,
|
# not in Python. In Python only \r (Carriage Return, 0xD) and \n (Line Feed,
|
||||||
# 0xA) are allowed to split lines.
|
# 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
|
# the default if nothing else has been set -> PEP 263
|
||||||
return encoding
|
return encoding
|
||||||
|
|
||||||
if isinstance(source, unicode):
|
if isinstance(source, str):
|
||||||
# only cast str/bytes
|
# only cast str/bytes
|
||||||
return source
|
return source
|
||||||
|
|
||||||
encoding = detect_encoding()
|
encoding = detect_encoding()
|
||||||
if not isinstance(encoding, unicode):
|
if not isinstance(encoding, str):
|
||||||
encoding = unicode(encoding, 'utf-8', 'replace')
|
encoding = str(encoding, 'utf-8', 'replace')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Cast to unicode
|
# Cast to unicode
|
||||||
return unicode(source, encoding, errors)
|
return str(source, encoding, errors)
|
||||||
except LookupError:
|
except LookupError:
|
||||||
if errors == 'replace':
|
if errors == 'replace':
|
||||||
# This is a weird case that can happen if the given encoding is not
|
# This is a weird case that can happen if the given encoding is not
|
||||||
# a valid encoding. This usually shouldn't happen with provided
|
# a valid encoding. This usually shouldn't happen with provided
|
||||||
# encodings, but can happen if somebody uses encoding declarations
|
# encodings, but can happen if somebody uses encoding declarations
|
||||||
# like `# coding: foo-8`.
|
# like `# coding: foo-8`.
|
||||||
return unicode(source, 'utf-8', errors)
|
return str(source, 'utf-8', errors)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
@@ -179,7 +177,7 @@ def parse_version_string(version=None):
|
|||||||
"""
|
"""
|
||||||
if version is None:
|
if version is None:
|
||||||
version = '%s.%s' % sys.version_info[:2]
|
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"')
|
raise TypeError('version must be a string like "3.8"')
|
||||||
|
|
||||||
return _parse_version(version)
|
return _parse_version(version)
|
||||||
|
|||||||
Reference in New Issue
Block a user