Skip to content

Replace assert(0) with Py_UNREACHABLE in Python/symtable.c #100577

Closed
@sobolevn

Description

@sobolevn

While looking at #87447 I've noticed that there are three places in cpython where assert(0) is used instead of Py_UNREACHABLE macro:

cpython/Python/symtable.c

Lines 1539 to 1542 in 984894a

/* We should always find either a FunctionBlock, ModuleBlock or ClassBlock
and should never fall to this case
*/
assert(0);

As the docs say:

Use this when you have a code path that cannot be reached by design.
For example, in the default: clause in a switch statement for which
all possible values are covered in case statements. Use this in places
where you might be tempted to put an assert(0) or abort() call.

The intent with Py_UNREACHABLE is clearer and error message is nicer.

Linked PRs

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions