forked from VimPlug/jedi
Simplify the Operator/Keyword string comparison.
This commit is contained in:
@@ -265,43 +265,16 @@ class String(Literal):
|
|||||||
__slots__ = ()
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
class Operator(_LeafWithoutNewlines):
|
class _StringComparisonMixin:
|
||||||
type = 'operator'
|
|
||||||
__slots__ = ()
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.value
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
"""
|
"""
|
||||||
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, Operator):
|
if isinstance(other, (str, unicode)):
|
||||||
return self is other
|
|
||||||
else:
|
|
||||||
return self.value == other
|
return self.value == other
|
||||||
|
|
||||||
def __ne__(self, other):
|
return self is 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
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
def __ne__(self, other):
|
||||||
"""Python 2 compatibility."""
|
"""Python 2 compatibility."""
|
||||||
@@ -311,6 +284,16 @@ class Keyword(_LeafWithoutNewlines):
|
|||||||
return hash(self.value)
|
return hash(self.value)
|
||||||
|
|
||||||
|
|
||||||
|
class Operator(_LeafWithoutNewlines, _StringComparisonMixin):
|
||||||
|
type = 'operator'
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
|
class Keyword(_LeafWithoutNewlines, _StringComparisonMixin):
|
||||||
|
type = 'keyword'
|
||||||
|
__slots__ = ()
|
||||||
|
|
||||||
|
|
||||||
class Scope(PythonBaseNode, DocstringMixin):
|
class Scope(PythonBaseNode, DocstringMixin):
|
||||||
"""
|
"""
|
||||||
Super class for the parser tree, which represents the state of a python
|
Super class for the parser tree, which represents the state of a python
|
||||||
|
|||||||
Reference in New Issue
Block a user