From a1829ecc7fe3675a897a793a7ad418de34ffac62 Mon Sep 17 00:00:00 2001 From: Dave Halter Date: Fri, 24 Jul 2020 01:51:30 +0200 Subject: [PATCH] Remove the unicode compatibility function --- parso/_compatibility.py | 6 ------ parso/python/tree.py | 3 +-- parso/tree.py | 2 -- parso/utils.py | 14 ++++++-------- 4 files changed, 7 insertions(+), 18 deletions(-) diff --git a/parso/_compatibility.py b/parso/_compatibility.py index 99a9702..35d83cc 100644 --- a/parso/_compatibility.py +++ b/parso/_compatibility.py @@ -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' diff --git a/parso/python/tree.py b/parso/python/tree.py index 00b3a12..06d4c96 100644 --- a/parso/python/tree.py +++ b/parso/python/tree.py @@ -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 diff --git a/parso/tree.py b/parso/tree.py index 045cd39..9105785 100644 --- a/parso/tree.py +++ b/parso/tree.py @@ -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: diff --git a/parso/utils.py b/parso/utils.py index 153b843..6751bfe 100644 --- a/parso/utils.py +++ b/parso/utils.py @@ -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)