Commit d9a032ce authored by Frank Bessou's avatar Frank Bessou 🍁
Browse files

feat: make internal types private

These types are not supposed to be accessed by client code.
parent 9ca83d742d80
......@@ -20,6 +20,7 @@
Note: this module uses __slots__ to limit memory usage.
"""
from rql.utils import VisitableMixIn
from typing import (
Tuple,
......@@ -43,6 +44,9 @@ if TYPE_CHECKING:
import rql
_Y = TypeVar("_Y", bound="BaseNode")
class BaseNode(VisitableMixIn):
__slots__: Iterable[str] = ("parent",)
......@@ -104,9 +108,7 @@ class BaseNode(VisitableMixIn):
return self.parent.scope
return None # should we return None or something else?
Y = TypeVar("Y", bound="BaseNode")
def get_nodes(self, klass: Type["Y"]) -> List["Y"]:
def get_nodes(self, klass: Type[_Y]) -> List[_Y]:
"""Return the list of nodes of a given class in the subtree.
:type klass: a node class (Relation, Constant, etc.)
......@@ -124,7 +126,7 @@ class BaseNode(VisitableMixIn):
stack += node.children
return result
def iget_nodes(self, klass: Type["Y"]) -> Iterator["Y"]:
def iget_nodes(self, klass: Type[_Y]) -> Iterator[_Y]:
"""Return an iterator over nodes of a given class in the subtree.
:type klass: a node class (Relation, Constant, etc.)
......
......@@ -134,13 +134,13 @@ def variable_refs(
yield vref
N = TypeVar("N", bound="BaseNode")
_N = TypeVar("_N", bound="BaseNode")
class HasOperatorAttribute(Protocol):
class _HasOperatorAttribute(Protocol):
operator: str
def iget_nodes(self, klass: Type["N"]) -> Iterator["N"]:
def iget_nodes(self, klass: Type["_N"]) -> Iterator["_N"]:
...
def get_type(
......@@ -153,20 +153,20 @@ class HasOperatorAttribute(Protocol):
class OperatorExpressionMixin:
def initargs(
self: HasOperatorAttribute, stmt: Optional["rql.stmts.Statement"]
self: _HasOperatorAttribute, stmt: Optional["rql.stmts.Statement"]
) -> Tuple[str, Optional[str]]:
"""return list of arguments to give to __init__ to clone this node"""
# "OperatorExpressionMixin" has no attribute "operator" [attr-defined]
return (self.operator, None)
def is_equivalent(self: HasOperatorAttribute, other: Any) -> bool:
def is_equivalent(self: _HasOperatorAttribute, other: Any) -> bool:
if not Node.is_equivalent(self, other):
return False
# "OperatorExpressionMixin" has no attribute "operator" [attr-defined]
return self.operator == other.operator
def get_description(
self: HasOperatorAttribute, mainindex: int, tr: TranslationFunction
self: _HasOperatorAttribute, mainindex: int, tr: TranslationFunction
) -> Optional[str]:
"""if there is a variable in the math expr used as rhs of a relation,
return the name of this relation, else return the type of the math
......@@ -184,15 +184,15 @@ class OperatorExpressionMixin:
return description
class HasRelationAttribute(Protocol):
class _HasRelationAttribute(Protocol):
def relation(
self,
) -> Optional["Relation"]:
...
class HasHand(Protocol):
parent: HasRelationAttribute
class _HasHand(Protocol):
parent: _HasRelationAttribute
def get_type(
self,
......@@ -207,7 +207,7 @@ class HSMixin:
__slots__: Iterable[str] = ()
def relation(self: HasHand) -> Optional["Relation"]:
def relation(self: _HasHand) -> Optional["Relation"]:
"""return the parent relation where self occurs or None"""
try:
return self.parent.relation()
......@@ -215,7 +215,7 @@ class HSMixin:
return None
def get_description(
self: HasHand, mainindex: int, tr: TranslationFunction
self: _HasHand, mainindex: int, tr: TranslationFunction
) -> Optional[str]:
mytype = self.get_type()
if mytype != "Any":
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment