mirror of https://github.com/python/cpython
gh-94808: Reorganize _make_posargs and mark unused code (GH-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.
This commit is contained in:
parent
99d945c0c0
commit
bd8c1f97e1
|
@ -543,7 +543,9 @@ _make_posargs(Parser *p,
|
||||||
asdl_arg_seq *plain_names,
|
asdl_arg_seq *plain_names,
|
||||||
asdl_seq *names_with_default,
|
asdl_seq *names_with_default,
|
||||||
asdl_arg_seq **posargs) {
|
asdl_arg_seq **posargs) {
|
||||||
if (plain_names != NULL && names_with_default != NULL) {
|
|
||||||
|
if (names_with_default != NULL) {
|
||||||
|
if (plain_names != NULL) {
|
||||||
asdl_arg_seq *names_with_default_names = _get_names(p, names_with_default);
|
asdl_arg_seq *names_with_default_names = _get_names(p, names_with_default);
|
||||||
if (!names_with_default_names) {
|
if (!names_with_default_names) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -551,15 +553,21 @@ _make_posargs(Parser *p,
|
||||||
*posargs = (asdl_arg_seq*)_PyPegen_join_sequences(
|
*posargs = (asdl_arg_seq*)_PyPegen_join_sequences(
|
||||||
p,(asdl_seq*)plain_names, (asdl_seq*)names_with_default_names);
|
p,(asdl_seq*)plain_names, (asdl_seq*)names_with_default_names);
|
||||||
}
|
}
|
||||||
else if (plain_names == NULL && names_with_default != NULL) {
|
else {
|
||||||
*posargs = _get_names(p, names_with_default);
|
*posargs = _get_names(p, names_with_default);
|
||||||
}
|
}
|
||||||
else if (plain_names != NULL && names_with_default == NULL) {
|
}
|
||||||
|
else {
|
||||||
|
if (plain_names != NULL) {
|
||||||
|
// With the current grammar, we never get here.
|
||||||
|
// If that has changed, remove the assert, and test thoroughly.
|
||||||
|
assert(0);
|
||||||
*posargs = plain_names;
|
*posargs = plain_names;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
*posargs = _Py_asdl_arg_seq_new(0, p->arena);
|
*posargs = _Py_asdl_arg_seq_new(0, p->arena);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return *posargs == NULL ? -1 : 0;
|
return *posargs == NULL ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue