/
name.py
55 lines (46 loc) · 1.51 KB
/
name.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from typing import Any, Optional
from tartiflette.language.ast.base import Node
__all__ = ("NameNode",)
class NameNode(Node):
"""
AST node representing a GraphQL name.
"""
__slots__ = ("value", "location")
def __init__(
self, value: str, location: Optional["Location"] = None
) -> None:
"""
:param value: value of the name
:param location: location of the name in the query/SDL
:type value: str
:type location: Optional[Location]
"""
self.value = value
self.location = location
def __eq__(self, other: Any) -> bool:
"""
Returns True if `other` instance is identical to `self`.
:param other: object instance to compare to `self`
:type other: Any
:return: whether or not `other` is identical to `self`
:rtype: bool
"""
return self is other or (
isinstance(other, NameNode)
and self.value == other.value
and self.location == other.location
)
def __repr__(self) -> str:
"""
Returns the representation of a NameNode instance.
:return: the representation of a NameNode instance
:rtype: str
"""
return "NameNode(value=%r, location=%r)" % (self.value, self.location)
def __str__(self) -> str:
"""
Returns a human-readable representation of the name.
:return: a human-readable representation of the name
:rtype: str
"""
return self.value