Commit 39705d45 authored by Nsukami Patrick's avatar Nsukami Patrick
Browse files

[mypy] Improve type hints inside rql/stmts.py module

- annotate schema as ISchema
- remove useless comments
- remove useless cast
- remove now useless type:ignore comments
parent 363e373faea0
......@@ -237,7 +237,7 @@ class Statement:
# default values for optional instance attributes, set on the instance when
# used
schema: Any = None # ISchema
schema: Optional["rql.interfaces.ISchema"] = None
annotated: bool = False # set by the annotator
if TYPE_CHECKING:
......@@ -288,14 +288,9 @@ class Union(Statement, Node):
child = Union()
for select in self.children[:]:
child.append(select)
# Argument 1 to "remove_select" of "Union"
# has incompatible type "BaseNode"; expected "Select" [arg-type]
self.remove_select(cast("rql.stmts.Select", select))
self.remove_select(select)
newselect: "rql.stmts.Select" = Select()
aliases: List["rql.nodes.VariableRef"] = []
# "BaseNode" has no attribute "selection"
# this attribute exists inside Select class, let's cast
select = cast("rql.stmts.Select", select)
for i in range(len(select.selection)):
aliases.append(nodes.VariableRef(newselect.make_variable()))
newselect.add_subquery(nodes.SubQuery(aliases, child), check=False)
......@@ -305,9 +300,7 @@ class Union(Statement, Node):
def _get_offset(self) -> int:
warn("offset is now a Select node attribute", DeprecationWarning, stacklevel=2)
# "BaseNode" has no attribute "offset"
# ScopeNode, Union, Select all has offset attribute
last_children = cast("rql.stmts.Select", self.children[-1])
last_children = self.children[-1]
return last_children.offset
def set_offset(self, offset: int) -> None:
......@@ -330,10 +323,10 @@ class Union(Statement, Node):
# but returning None breaks the tests
def set_limit(self, limit: int) -> Optional["rql.stmts.Union"]:
if len(self.children) == 1:
self.children[-1].set_limit(limit) # type: ignore[attr-defined]
self.children[-1].set_limit(limit)
return self
self.wrap_selects()
self.children[0].set_limit(limit) # type: ignore[attr-defined]
self.children[0].set_limit(limit)
return None
# Argument 2 to "property" has incompatible type "Callable[[rql.stmts.Union, 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