You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Add checks for empty/unnamed arguments to make_rst.py
This commit is contained in:
@@ -63,7 +63,7 @@ PropertyInfo MethodBind::get_argument_info(int p_argument) const {
|
|||||||
|
|
||||||
PropertyInfo info = _gen_argument_type_info(p_argument);
|
PropertyInfo info = _gen_argument_type_info(p_argument);
|
||||||
#ifdef DEBUG_METHODS_ENABLED
|
#ifdef DEBUG_METHODS_ENABLED
|
||||||
info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("arg" + itos(p_argument));
|
info.name = p_argument < arg_names.size() ? String(arg_names[p_argument]) : String("_unnamed_arg" + itos(p_argument));
|
||||||
#endif
|
#endif
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class State:
|
|||||||
|
|
||||||
def parse_class(self, class_root: ET.Element, filepath: str) -> None:
|
def parse_class(self, class_root: ET.Element, filepath: str) -> None:
|
||||||
class_name = class_root.attrib["name"]
|
class_name = class_root.attrib["name"]
|
||||||
|
self.current_class = class_name
|
||||||
|
|
||||||
class_def = ClassDef(class_name)
|
class_def = ClassDef(class_name)
|
||||||
self.classes[class_name] = class_def
|
self.classes[class_name] = class_def
|
||||||
@@ -126,7 +127,7 @@ class State:
|
|||||||
else:
|
else:
|
||||||
return_type = TypeName("void")
|
return_type = TypeName("void")
|
||||||
|
|
||||||
params = parse_arguments(constructor)
|
params = self.parse_arguments(constructor, "constructor")
|
||||||
|
|
||||||
desc_element = constructor.find("description")
|
desc_element = constructor.find("description")
|
||||||
method_desc = None
|
method_desc = None
|
||||||
@@ -154,7 +155,7 @@ class State:
|
|||||||
else:
|
else:
|
||||||
return_type = TypeName("void")
|
return_type = TypeName("void")
|
||||||
|
|
||||||
params = parse_arguments(method)
|
params = self.parse_arguments(method, "method")
|
||||||
|
|
||||||
desc_element = method.find("description")
|
desc_element = method.find("description")
|
||||||
method_desc = None
|
method_desc = None
|
||||||
@@ -182,7 +183,7 @@ class State:
|
|||||||
else:
|
else:
|
||||||
return_type = TypeName("void")
|
return_type = TypeName("void")
|
||||||
|
|
||||||
params = parse_arguments(operator)
|
params = self.parse_arguments(operator, "operator")
|
||||||
|
|
||||||
desc_element = operator.find("description")
|
desc_element = operator.find("description")
|
||||||
method_desc = None
|
method_desc = None
|
||||||
@@ -230,7 +231,7 @@ class State:
|
|||||||
annotation_name = annotation.attrib["name"]
|
annotation_name = annotation.attrib["name"]
|
||||||
qualifiers = annotation.get("qualifiers")
|
qualifiers = annotation.get("qualifiers")
|
||||||
|
|
||||||
params = parse_arguments(annotation)
|
params = self.parse_arguments(annotation, "annotation")
|
||||||
|
|
||||||
desc_element = annotation.find("description")
|
desc_element = annotation.find("description")
|
||||||
annotation_desc = None
|
annotation_desc = None
|
||||||
@@ -254,7 +255,7 @@ class State:
|
|||||||
print_error('{}.xml: Duplicate signal "{}".'.format(class_name, signal_name), self)
|
print_error('{}.xml: Duplicate signal "{}".'.format(class_name, signal_name), self)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
params = parse_arguments(signal)
|
params = self.parse_arguments(signal, "signal")
|
||||||
|
|
||||||
desc_element = signal.find("description")
|
desc_element = signal.find("description")
|
||||||
signal_desc = None
|
signal_desc = None
|
||||||
@@ -302,6 +303,32 @@ class State:
|
|||||||
if link.text is not None:
|
if link.text is not None:
|
||||||
class_def.tutorials.append((link.text.strip(), link.get("title", "")))
|
class_def.tutorials.append((link.text.strip(), link.get("title", "")))
|
||||||
|
|
||||||
|
self.current_class = ""
|
||||||
|
|
||||||
|
def parse_arguments(self, root: ET.Element, context: str) -> List["ParameterDef"]:
|
||||||
|
param_elements = root.findall("argument")
|
||||||
|
params: Any = [None] * len(param_elements)
|
||||||
|
|
||||||
|
for param_index, param_element in enumerate(param_elements):
|
||||||
|
param_name = param_element.attrib["name"]
|
||||||
|
index = int(param_element.attrib["index"])
|
||||||
|
type_name = TypeName.from_element(param_element)
|
||||||
|
default = param_element.get("default")
|
||||||
|
|
||||||
|
if param_name.strip() == "" or param_name.startswith("_unnamed_arg"):
|
||||||
|
print_error(
|
||||||
|
'{}.xml: Empty argument name in {} "{}" at position {}.'.format(
|
||||||
|
self.current_class, context, root.attrib["name"], param_index
|
||||||
|
),
|
||||||
|
self,
|
||||||
|
)
|
||||||
|
|
||||||
|
params[index] = ParameterDef(param_name, type_name, default)
|
||||||
|
|
||||||
|
cast: List[ParameterDef] = params
|
||||||
|
|
||||||
|
return cast
|
||||||
|
|
||||||
def sort_classes(self) -> None:
|
def sort_classes(self) -> None:
|
||||||
self.classes = OrderedDict(sorted(self.classes.items(), key=lambda t: t[0]))
|
self.classes = OrderedDict(sorted(self.classes.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
@@ -440,22 +467,6 @@ def print_error(error: str, state: State) -> None:
|
|||||||
state.num_errors += 1
|
state.num_errors += 1
|
||||||
|
|
||||||
|
|
||||||
def parse_arguments(root: ET.Element) -> List[ParameterDef]:
|
|
||||||
param_elements = root.findall("argument")
|
|
||||||
params: Any = [None] * len(param_elements)
|
|
||||||
for param_element in param_elements:
|
|
||||||
param_name = param_element.attrib["name"]
|
|
||||||
index = int(param_element.attrib["index"])
|
|
||||||
type_name = TypeName.from_element(param_element)
|
|
||||||
default = param_element.get("default")
|
|
||||||
|
|
||||||
params[index] = ParameterDef(param_name, type_name, default)
|
|
||||||
|
|
||||||
cast: List[ParameterDef] = params
|
|
||||||
|
|
||||||
return cast
|
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
|
# Enable ANSI escape code support on Windows 10 and later (for colored console output).
|
||||||
# <https://bugs.python.org/issue29059>
|
# <https://bugs.python.org/issue29059>
|
||||||
|
|||||||
Reference in New Issue
Block a user