Swift iOS Ambiguous use of '==' when comparing two PythonObject in PythonKit

52 Views Asked by At

Im currently using the PythonKit SPM Package to interact with Python, I'm doing this due to a Algorithm that was written in Python is required by my iOS App to work correctly.

Base on the PythonKit Library I'm trying to Compare two PythonObjects using the '==' Operator, Swift Compiler complains that '==' is Ambiguous. I've tried digging into the library to find a equals function instead of using the '==' Operator, but to no avail.

The Library has an overridden '==' Operator defined like so

public static func == (lhs: PythonObject, rhs: PythonObject) -> Bool {
    return lhs.compared(to: rhs, byOp: Py_EQ)
}

But this operator is defined twice within the library and I have a feeling this is why I'm getting the Operator '==' is Ambiguous.

Has anyone else run into this issue or know of any possible fixes for this problem?

1

There are 1 best solutions below

0
Ptit Xav On BEST ANSWER

If the code is when you are using the == operator, then you better define the result of == as a bool :

let result: Bool = pyobj1 == pyobj2

This is because the == method has 2 different return type : Bool and PythonObject and the compiler may not be sure of which of the 2 implementation to use.