Skip to content

Commit 0448bdc

Browse files
mjdominusestyxx
authored andcommitted
pythongh-94808: Reorganize _make_posargs and mark unused code (pythonGH-119227)
* Reorganize four-way if-elsif-elsif-elsif as nested if-elses * Mark unused branch in _make_posargs `names_with_default` is never `NULL`, even if there are no names with defaults. In that case it points to a structure with `size` zero. Rather than eliminating the branch, we leave it behind with an `assert(0)` in case a future change to the grammar exercises the branch.
1 parent f01bcec commit 0448bdc

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

Parser/action_helpers.c

+21-13
Original file line numberDiff line numberDiff line change
@@ -543,22 +543,30 @@ _make_posargs(Parser *p,
543543
asdl_arg_seq *plain_names,
544544
asdl_seq *names_with_default,
545545
asdl_arg_seq **posargs) {
546-
if (plain_names != NULL && names_with_default != NULL) {
547-
asdl_arg_seq *names_with_default_names = _get_names(p, names_with_default);
548-
if (!names_with_default_names) {
549-
return -1;
546+
547+
if (names_with_default != NULL) {
548+
if (plain_names != NULL) {
549+
asdl_arg_seq *names_with_default_names = _get_names(p, names_with_default);
550+
if (!names_with_default_names) {
551+
return -1;
552+
}
553+
*posargs = (asdl_arg_seq*)_PyPegen_join_sequences(
554+
p,(asdl_seq*)plain_names, (asdl_seq*)names_with_default_names);
555+
}
556+
else {
557+
*posargs = _get_names(p, names_with_default);
550558
}
551-
*posargs = (asdl_arg_seq*)_PyPegen_join_sequences(
552-
p,(asdl_seq*)plain_names, (asdl_seq*)names_with_default_names);
553-
}
554-
else if (plain_names == NULL && names_with_default != NULL) {
555-
*posargs = _get_names(p, names_with_default);
556-
}
557-
else if (plain_names != NULL && names_with_default == NULL) {
558-
*posargs = plain_names;
559559
}
560560
else {
561-
*posargs = _Py_asdl_arg_seq_new(0, p->arena);
561+
if (plain_names != NULL) {
562+
// With the current grammar, we never get here.
563+
// If that has changed, remove the assert, and test thoroughly.
564+
assert(0);
565+
*posargs = plain_names;
566+
}
567+
else {
568+
*posargs = _Py_asdl_arg_seq_new(0, p->arena);
569+
}
562570
}
563571
return *posargs == NULL ? -1 : 0;
564572
}

0 commit comments

Comments
 (0)