Skip to content

Clarify pylong_as_bool invalid-input return value #780

Description

@coderabbitai

Summary

Evaluate the invalid-input return value in pylong_as_bool in plugins/python/src/modulewrap.cpp.

The function sets a Python ValueError and currently returns static_cast<bool>(-1). In C++, that conversion yields true, which makes the returned value look like a successful boolean result if it is observed independently of the pending Python exception.

Required changes

Define and document the intended error-path contract for pylong_as_bool, then update the implementation accordingly. Consider whether the return should be simply true, false, or whether the function/API should be structured so that an error cannot be represented by a boolean return value.

Rationale

PR #771 replaced a C-style cast with static_cast<bool>(-1) to satisfy modernize-avoid-c-style-cast. The modernization preserves existing behavior, but the resulting expression exposes an unclear sentinel/error convention that should be reviewed separately.

Affected area

  • plugins/python/src/modulewrap.cpp
  • pylong_as_bool(PyObject*)
  • Python-to-C++ boolean conversion through the BASIC_CONVERTER machinery

Backlinks

Requested by @knoepfel.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions