Skip to content

fix(stl): reject non-iterable classes named like builtin iterables - #6243

Open
kroplabeskidu wants to merge 2 commits into
pybind:masterfrom
kroplabeskidu:fix-stl-non-iterable-tp-name
Open

kroplabeskidu wants to merge 2 commits into
pybind:masterfrom
kroplabeskidu:fix-stl-non-iterable-tp-name

Conversation

@kroplabeskidu

Copy link
Copy Markdown

Description

Item 13 from #6159. The STL casters accept some builtin iterables by matching tp_name (map, zip, dict_keys, dict_values, dict_items). A user class with one of those names passes the check even if it isn't iterable. Release builds then raise TypeError: 'map' object is not iterable from inside the caster, which stops overload resolution. The review reports that debug builds hit the isinstance<iterable> assert and abort; I only ran this test on a release build before the fix.

A name match now also requires the object to be iterable, so the caster returns false and the next overload gets a chance.

The review suggests rejecting heap types. I used an iterability check because it doesn't rely on how PyPy and GraalPy flag these types. As a result, an iterable user class named map is still accepted, same as before.

Suggested changelog entry:

  • STL casters now reject non-iterable user classes named like builtin iterables, instead of raising during overload resolution.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant