Commit 68a599a6 authored by Nsukami Patrick's avatar Nsukami Patrick
Browse files

[mypy]: add IsASelectionManager protocol

update undo_manager property, type:
  self._undo_manager as SelectionManager
and fix:
  rql/stmts.py:424: error: Cannot determine type of "_undo_manager" [has-type]

rewrite the undo_manager function and make sure it always returns a SelectionManager
parent ff2e7ec69a51
......@@ -174,7 +174,6 @@ class HasOperatorAttribute(Protocol):
) -> str:
...
# AnyScopeNode is the Union of all ScopeNode child classes
AnyScopeNode = Union_[
"rql.stmts.Set",
......@@ -183,3 +182,25 @@ AnyScopeNode = Union_[
"rql.stmts.Select",
"rql.stmts.Select",
]
Op = Union_[
"rql.undo.NodeOperation",
"rql.undo.MakeVarOperation",
"rql.undo.UndefineVarOperation",
"rql.undo.SelectVarOperation",
"rql.undo.UnselectVarOperation",
"rql.undo.AddNodeOperation",
"rql.undo.ReplaceNodeOperation",
"rql.undo.RemoveNodeOperation",
"rql.undo.AddSortOperation",
"rql.undo.RemoveSortOperation",
"rql.undo.AddGroupOperation",
"rql.undo.RemoveGroupOperation",
"rql.undo.SetDistinctOperation",
"rql.undo.SetOffsetOperation",
"rql.undo.SetLimitOperation",
"rql.undo.SetOptionalOperation",
"rql.undo.SetHavingOperation",
"rql.undo.AppendSelectOperation",
"rql.undo.RemoveSelectOperation",
]
......@@ -469,14 +469,13 @@ class Union(Statement, Node):
# don't use @cached: we want to be able to disable it while this must still
# be cached
@property
def undo_manager(self):
try:
return self._undo_manager
except AttributeError:
from rql.undo import SelectionManager
self._undo_manager = SelectionManager(self)
return self._undo_manager
def undo_manager(self) -> "rql.undo.SelectionManager":
from rql.undo import SelectionManager
undo_manager = getattr(self, "_undo_manager", None)
if undo_manager:
return undo_manager
self._undo_manager = SelectionManager(self)
return self._undo_manager
@property
def should_register_op(self):
......@@ -505,7 +504,6 @@ class Union(Statement, Node):
def append_select(self, select: "rql.stmts.Select") -> None:
if self.should_register_op:
from rql.undo import AppendSelectOperation
self.undo_manager.add_operation(AppendSelectOperation(self, select))
self.children.append(select)
......@@ -513,7 +511,6 @@ class Union(Statement, Node):
idx: int = self.children.index(select)
if self.should_register_op:
from rql.undo import RemoveSelectOperation
self.undo_manager.add_operation(RemoveSelectOperation(self, select, idx))
self.children.pop(idx)
......
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