pybind / pybind/pybind11

Cannot call embedded function from within class function

Open
#1,452 5 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

I've written a c++ binding that allows me to post a simple message such that:

import foo
foo.func("message")

when called in python will post "message".

However, if I call the same embedded function from within a class method such as:

import foo

class bar(object):
  def func2(self):
    foo.func("message")

I will get an exception error_already_set. This occurs if I call the function from python or from c++.
I'm not sure if this is a pybind11 bug, or if I just missed something.

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 by reproducing the two Python examples shown in the issue, including calling the method from C++ if possible, and capture the full error_already_set details. Determine whether the failure is specific to invoking foo.func inside a class method; done means that invocation works consistently or the issue has a documented, reproducible limitation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.