Skip to content

Commit

Permalink
Fix error from PythonProxyObject with PyBind11 update to 2.7.1 that r…
Browse files Browse the repository at this point in the history
…esults in an 'unhashable type' for PythonProxyObject.

(See pybind/pybind11#2291 )

Signed-off-by: Steve Pham <[email protected]>
  • Loading branch information
spham-amzn committed Jul 18, 2022
1 parent 30f9001 commit c154561
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Gems/EditorPythonBindings/Code/Source/PythonProxyObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,12 @@ namespace EditorPythonBindings
return GetWrappedObjectRepr();
}

pybind11::ssize_t PythonProxyObject::GetWrappedObjectHash()
{
pybind11::object result = GetWrappedObjectRepr();
return pybind11::hash(result.release());
}

void PythonProxyObject::ReleaseWrappedObject()
{
if (m_wrappedObject.IsValid() && m_ownership == Ownership::Owned)
Expand Down Expand Up @@ -976,6 +982,7 @@ namespace EditorPythonBindings
})
.def("__setattr__", &PythonProxyObject::SetPropertyValue)
.def("__getattr__", &PythonProxyObject::GetPropertyValue)
.def("__hash__", &PythonProxyObject::GetWrappedObjectHash)
.def(Builtins::s_repr, [](PythonProxyObject& self)
{
return self.GetWrappedObjectRepr();
Expand Down
4 changes: 4 additions & 0 deletions Gems/EditorPythonBindings/Code/Source/PythonProxyObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ namespace EditorPythonBindings
//! Gets the wrapped object's __str__
pybind11::object GetWrappedObjectStr();

//! Gets the wrapped object's __hash__
pybind11::ssize_t GetWrappedObjectHash();


protected:
void PrepareWrappedObject(const AZ::BehaviorClass& behaviorClass);
void ReleaseWrappedObject();
Expand Down

0 comments on commit c154561

Please sign in to comment.