pybind / pybind/pybind11

Multiple inheritance error with __slots__

Open
#930 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
18k
Forks
2.3k
Avg merge
5d 17h
Merged PRs (30d)
10

Description

When creating a Python class from two base classes, one of which is a Python class that uses __slots__ and the other a pybind11 generated class, I get the Python error:

TypeError: multiple bases have instance lay-out conflict

There is no error if the Python class does not use __slots__. Below is code to reproduce. I am using the master branch of pybind11. Error is seen with Python 2.7 and Python 3.6.

import example

class MyClass0(object):
    __slots__ = ["name"]  # Comment this line to avoid error
    def __init__(self, name):
        self.name = name

class TestClass(MyClass0, example.Base0):
    def __init__(self):
        pass
#include <pybind11/pybind11.h>
namespace py = pybind11;

struct Base0 { };

PYBIND11_MODULE(example, m)
{
  py::class_<Base0>(m, "Base0");
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Python reproducer defining MyClass0 with slots and TestClass inheriting from MyClass0 and example.Base0, then build and run the shown pybind11 module containing Base0. Compare the result with slots removed; the issue is resolved when the reported multiple-bases instance-layout conflict is addressed for the supplied case.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.