0

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?

2
  • 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. Commented Apr 23, 2023 at 9:21
  • @PtitXav this worked thank you very much. If you want, change your comment to an answer and ill give it a tick for those internet points Commented Apr 23, 2023 at 9:34

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.