Skip to content

Commit

Permalink
Fix formatting and mypy, add visit method back to stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
theCapypara committed Jul 16, 2024
1 parent fc0a0cb commit 40f4ad5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions explorerscript_parser/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -780,6 +780,7 @@ class ExplorerScriptBaseVisitor:
def visitString_value(self, context: ExplorerScriptParser.String_valueContext) -> Any: ...
def visitCtx_header(self, context: ExplorerScriptParser.Ctx_headerContext) -> Any: ...
def visitFor_target_def_target(self, context: ExplorerScriptParser.For_target_def_targetContext) -> Any: ...
def visit(self, tree: Antlr4ParseTree) -> Any: ...
def visitChildren(self, node: Antlr4ParseTree) -> Any: ...
def defaultResult(self) -> Any: ...
def aggregateResult(self, aggregate: Any, nextResult: Any) -> Any: ...
Expand Down Expand Up @@ -1005,6 +1006,7 @@ class SsbScriptBaseVisitor:
def visitString_value(self, context: SsbScriptParser.String_valueContext) -> Any: ...
def visitCtx_header(self, context: SsbScriptParser.Ctx_headerContext) -> Any: ...
def visitFor_target_def_target(self, context: SsbScriptParser.For_target_def_targetContext) -> Any: ...
def visit(self, tree: Antlr4ParseTree) -> Any: ...
def visitChildren(self, node: Antlr4ParseTree) -> Any: ...
def defaultResult(self) -> Any: ...
def aggregateResult(self, aggregate: Any, nextResult: Any) -> Any: ...
Expand Down
9 changes: 7 additions & 2 deletions generate_parser_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def generate_bindings(target: str, classes: Classes, visitor_methods: list[Metho
f' .def("{method_name}", py::overload_cast<{method["params"].split(' ')[0]}>(&{class_name}::{method_name}), py::return_value_policy::reference_internal)'
)
else:
bindings.append(f' .def("{method_name}", py::overload_cast<>(&{class_name}::{method_name}), py::return_value_policy::reference_internal)')
bindings.append(
f' .def("{method_name}", py::overload_cast<>(&{class_name}::{method_name}), py::return_value_policy::reference_internal)'
)
else:
method = overloads[0]
bindings.append(
Expand All @@ -89,7 +91,9 @@ def generate_bindings(target: str, classes: Classes, visitor_methods: list[Metho

bindings.append(";")

bindings.append(f'py::class_<{target}BaseVisitor, Py{target}BaseVisitor, antlr4::tree::ParseTreeVisitor>(m, "{target}BaseVisitor")')
bindings.append(
f'py::class_<{target}BaseVisitor, Py{target}BaseVisitor, antlr4::tree::ParseTreeVisitor>(m, "{target}BaseVisitor")'
)
bindings.append(" .def(py::init<>())")
bindings.append(f' .def("visitChildren", []({target}BaseVisitor& self, antlr4::tree::ParseTree* node) {{')
bindings.append(" return std::any_cast<pybind11::object>(self.visitChildren(node));")
Expand Down Expand Up @@ -287,6 +291,7 @@ def generate_stubs(target: str, classes: Classes, visitor_methods: list[MethodDe
f" def {method['method_name']}(self{maybe_comma}{convert_cpp_sig_to_py(target, method['params'])}) -> {convert_cpp_ty_to_py(target, return_type)}: ..."
)

bindings.append(" def visit(self, tree: Antlr4ParseTree) -> Any: ...")
bindings.append(" def visitChildren(self, node: Antlr4ParseTree) -> Any: ...")
bindings.append(" def defaultResult(self) -> Any: ...")
bindings.append(" def aggregateResult(self, aggregate: Any, nextResult: Any) -> Any: ...")
Expand Down
5 changes: 1 addition & 4 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ namespace_packages = True
check_untyped_defs = True
allow_untyped_defs = False
allow_any_generics = False
exclude = explorerscript/antlr

[mypy-explorerscript.antlr.*]
ignore_errors = True
exclude = antlr4
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ namespaces = false
[tool.ruff]
line-length = 120
extend-exclude = [
"explorerscript/antlr/*"
"antlr4/*"
]

[tools.ruff.lint]
Expand Down

0 comments on commit 40f4ad5

Please sign in to comment.