<h3 dir="auto">Describe the issue:</h3>
<p dir="auto">Following code does not raise any exception. It looks like something wrong with <code class="notranslate">==</code> operator.</p>
<h3 dir="auto">Reproduce the code example:</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
keys = {np.int8: 1}.keys()
assert not np.dtype(&quot;int8&quot;) in keys
assert     np.dtype(&quot;int8&quot;) in list(keys)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-s1">keys</span> <span class="pl-c1">=</span> {<span class="pl-s1">np</span>.<span class="pl-s1">int8</span>: <span class="pl-c1">1</span>}.<span class="pl-en">keys</span>()
<span class="pl-k">assert</span> <span class="pl-c1">not</span> <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s">"int8"</span>) <span class="pl-c1">in</span> <span class="pl-s1">keys</span>
<span class="pl-k">assert</span>     <span class="pl-s1">np</span>.<span class="pl-en">dtype</span>(<span class="pl-s">"int8"</span>) <span class="pl-c1">in</span> <span class="pl-en">list</span>(<span class="pl-s1">keys</span>)</pre></div>
<h3 dir="auto">Error message:</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">NumPy/Python version information:</h3>
<p dir="auto">1.22.3 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0]</p>
<h3 dir="auto">Context for the issue:</h3>
<p dir="auto"><em>No response</em></p>
<p dir="auto">It seems that <code class="notranslate">np.dtype(...)</code> does not produce consistent hashes and does not equal the hash of the contained dtype. I feel like these should be consistent with each other so that the following will return true:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="np.empty(1).dtype in {np.float32, np.float64}  # False"><pre class="notranslate"><code class="notranslate">np.empty(1).dtype in {np.float32, np.float64}  # False
</code></pre></div>
<h3 dir="auto">Reproducing code example:</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [1]: np.float64 == np.dtype(np.float64)
Out[1]: True

In [2]: np.float64 in {np.dtype(np.float64)}
Out[2]: False

In [3]: hash(np.float64)
Out[3]: 8793996338852

In [4]: hash(np.dtype(np.float64))
Out[4]: 3855163183283070272"><pre class="notranslate"><code class="notranslate">In [1]: np.float64 == np.dtype(np.float64)
Out[1]: True

In [2]: np.float64 in {np.dtype(np.float64)}
Out[2]: False

In [3]: hash(np.float64)
Out[3]: 8793996338852

In [4]: hash(np.dtype(np.float64))
Out[4]: 3855163183283070272
</code></pre></div>
<p dir="auto"><code class="notranslate">hash(np.dtype(np.float64))</code> returns a different value when called in different runtimes too.</p>
<hr>
<p dir="auto">Would this be worth fixing?</p>