<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>BioErrorLog</author_name>
  <author_url>https://blog.hatena.ne.jp/BioErrorLog/</author_url>
  <blog_title>BioErrorLog Tech Blog</blog_title>
  <blog_url>https://www.bioerrorlog.work/</blog_url>
  <categories>
    <anon>Python</anon>
  </categories>
  <description>Pythonで独自に定義したユーザー定義クラスのオブジェクト同士を等価比較する方法を整理します。 はじめに Pythonでユーザー定義クラスのオブジェクトを等価比較する __eq__メソッドでインスタンス変数を比較する __eq__メソッドで__dict__を比較する 同一クラスかを比較する 同一クラスでない時はNotImplementedを投げる おわりに 参考 はじめに Pythonでは、ユーザー定義クラスは等価演算子で比較することが出来ません。 例えば、次のようなクラス/pytestコードを定義した場合、オブジェクト比較部分のassertでエラーが発生します。 class MyClass…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fwww.bioerrorlog.work%2Fentry%2Fpython-class-obj-equality&quot; title=&quot;Pythonでユーザー定義クラスのオブジェクトを等価比較する - BioErrorLog Tech Blog&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url>https://cdn-ak.f.st-hatena.com/images/fotolife/B/BioErrorLog/20210814/20210814203332.png</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2021-08-14 20:33:59</published>
  <title>Pythonでユーザー定義クラスのオブジェクトを等価比較する</title>
  <type>rich</type>
  <url>https://www.bioerrorlog.work/entry/python-class-obj-equality</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
