Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How to Compare Reference Equality of Value Objects in pythonnet Without Using Obsolete PyObject.Handle#2604

Answeredbylostmsu
ljnober asked this question inQ&A
Discussion options

When working with value objects converted from pybind11, some objects override the equality operator (==). In such cases, I need to compare objects based on reference equality instead of value equality. In Python, this is typically done using id(obj) or the is operator to check if two variables point to the same object .

In pythonnet, I attempted to use PyObject.Handle for this purpose, but it is marked as obsolete . What is the recommended way to achieve reference equality comparisons in pythonnet now? For example:

  • Can Python’s built-in id() function be used directly?
  • Are there alternative APIs in pythonnet to replace PyObject.Handle?
    This is critical for ensuring correct comparisons of objects where value-based equality is intentionally overridden.
You must be logged in to vote

There's aPythonReferenceComparer.Instance of typeIEqualityComparer<PyObject>

Replies: 1 comment 1 reply

Comment options

There's aPythonReferenceComparer.Instance of typeIEqualityComparer<PyObject>

You must be logged in to vote
1 reply
@ljnober
Comment options

Thx,i replaced it with this method and it's working.

Answer selected byljnober
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
2 participants
@ljnober@lostmsu
Converted from issue

This discussion was converted from issue #2603 on July 16, 2025 20:46.


[8]ページ先頭

©2009-2025 Movatter.jp