mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-12 09:17:42 +00:00
Don't allow mixed static/non-static overloads
We currently fail at runtime when trying to call a method that is overloaded with both static and non-static methods. This is something python won't allow: the object is either a function or an instance, and can't be both.
This commit is contained in:
@@ -318,6 +318,15 @@ protected:
|
||||
m_ptr = rec->sibling.ptr();
|
||||
inc_ref();
|
||||
chain_start = chain;
|
||||
if (chain->is_method != rec->is_method)
|
||||
pybind11_fail("overloading a method with both static and instance methods is not supported; "
|
||||
#if defined(NDEBUG)
|
||||
"compile in debug mode for more details"
|
||||
#else
|
||||
"error while attempting to bind " + std::string(rec->is_method ? "instance" : "static") + " method " +
|
||||
std::string(pybind11::str(rec->scope.attr("__name__"))) + "." + std::string(rec->name) + signature
|
||||
#endif
|
||||
);
|
||||
while (chain->next)
|
||||
chain = chain->next;
|
||||
chain->next = rec;
|
||||
|
||||
Reference in New Issue
Block a user