1
0
forked from VimPlug/jedi

Simplify the Operator/Keyword string comparison.

This commit is contained in:
Dave Halter
2017-04-12 19:11:14 +02:00
parent a0b65b52c6
commit 73a38267cf

View File

@@ -265,43 +265,16 @@ class String(Literal):
__slots__ = ()
class Operator(_LeafWithoutNewlines):
type = 'operator'
__slots__ = ()
def __str__(self):
return self.value
class _StringComparisonMixin:
def __eq__(self, other):
"""
Make comparisons with strings easy.
Improves the readability of the parser.
"""
if isinstance(other, Operator):
return self is other
else:
if isinstance(other, (str, unicode)):
return self.value == other
def __ne__(self, other):
"""Python 2 compatibility."""
return self.value != other
def __hash__(self):
return hash(self.value)
class Keyword(_LeafWithoutNewlines):
type = 'keyword'
__slots__ = ()
def __eq__(self, other):
"""
Make comparisons with strings easy.
Improves the readability of the parser.
"""
if isinstance(other, Keyword):
return self is other
return self.value == other
return self is other
def __ne__(self, other):
"""Python 2 compatibility."""
@@ -311,6 +284,16 @@ class Keyword(_LeafWithoutNewlines):
return hash(self.value)
class Operator(_LeafWithoutNewlines, _StringComparisonMixin):
type = 'operator'
__slots__ = ()
class Keyword(_LeafWithoutNewlines, _StringComparisonMixin):
type = 'keyword'
__slots__ = ()
class Scope(PythonBaseNode, DocstringMixin):
"""
Super class for the parser tree, which represents the state of a python