mirror of
https://github.com/davidhalter/parso.git
synced 2026-05-17 22:10:01 +08:00
Remove utf8_repr from _compatibility.py
This commit is contained in:
@@ -44,24 +44,6 @@ def u(string):
|
|||||||
return string
|
return string
|
||||||
|
|
||||||
|
|
||||||
def utf8_repr(func):
|
|
||||||
"""
|
|
||||||
``__repr__`` methods in Python 2 don't allow unicode objects to be
|
|
||||||
returned. Therefore cast them to utf-8 bytes in this decorator.
|
|
||||||
"""
|
|
||||||
def wrapper(self):
|
|
||||||
result = func(self)
|
|
||||||
if isinstance(result, unicode):
|
|
||||||
return result.encode('utf-8')
|
|
||||||
else:
|
|
||||||
return result
|
|
||||||
|
|
||||||
if sys.version_info.major >= 3:
|
|
||||||
return func
|
|
||||||
else:
|
|
||||||
return wrapper
|
|
||||||
|
|
||||||
|
|
||||||
if sys.version_info < (3, 5):
|
if sys.version_info < (3, 5):
|
||||||
"""
|
"""
|
||||||
A super-minimal shim around listdir that behave like
|
A super-minimal shim around listdir that behave like
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from collections import Mapping
|
from collections import Mapping
|
||||||
|
|
||||||
from parso._compatibility import utf8_repr, unicode
|
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
|
||||||
@@ -175,7 +175,6 @@ class EndMarker(_LeafWithoutNewlines):
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
type = 'endmarker'
|
type = 'endmarker'
|
||||||
|
|
||||||
@utf8_repr
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: prefix=%s end_pos=%s>" % (
|
return "<%s: prefix=%s end_pos=%s>" % (
|
||||||
type(self).__name__, repr(self.prefix), self.end_pos
|
type(self).__name__, repr(self.prefix), self.end_pos
|
||||||
@@ -187,7 +186,6 @@ class Newline(PythonLeaf):
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
type = 'newline'
|
type = 'newline'
|
||||||
|
|
||||||
@utf8_repr
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s: %s>" % (type(self).__name__, repr(self.value))
|
return "<%s: %s>" % (type(self).__name__, repr(self.value))
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -1,7 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from abc import abstractmethod, abstractproperty
|
from abc import abstractmethod, abstractproperty
|
||||||
|
|
||||||
from parso._compatibility import utf8_repr, encoding
|
from parso._compatibility import encoding
|
||||||
from parso.utils import split_lines
|
from parso.utils import split_lines
|
||||||
|
|
||||||
|
|
||||||
@@ -238,7 +238,6 @@ class Leaf(NodeOrLeaf):
|
|||||||
end_pos_column = len(lines[-1])
|
end_pos_column = len(lines[-1])
|
||||||
return end_pos_line, end_pos_column
|
return end_pos_line, end_pos_column
|
||||||
|
|
||||||
@utf8_repr
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
value = self.value
|
value = self.value
|
||||||
if not value:
|
if not value:
|
||||||
@@ -333,7 +332,6 @@ class BaseNode(NodeOrLeaf):
|
|||||||
def get_last_leaf(self):
|
def get_last_leaf(self):
|
||||||
return self.children[-1].get_last_leaf()
|
return self.children[-1].get_last_leaf()
|
||||||
|
|
||||||
@utf8_repr
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
code = self.get_code().replace('\n', ' ').replace('\r', ' ').strip()
|
code = self.get_code().replace('\n', ' ').replace('\r', ' ').strip()
|
||||||
if not sys.version_info.major >= 3:
|
if not sys.version_info.major >= 3:
|
||||||
|
|||||||
Reference in New Issue
Block a user