New GitHub issue #119260 from JelleZijlstra:<br>
<hr>
<pre>
# Bug report
### Bug description:
If a dataclass has a subclass that is not itself a dataclass, `is_dataclass()` returns True on the subclass and its instances:
```python
from dataclasses import dataclass, is_dataclass
@dataclass
class X:
y: int
class Z(X):
pass
print(is_dataclass(Z)) # True
print(is_dataclass(Z())) # True
```
Documentation of is_dataclass() for reference: https://docs.python.org/3.13/library/dataclasses.html#dataclasses.is_dataclass
Intuitively this seems wrong: Z is not itself a dataclass. In pyanalyze I wrote a replacement for `is_dataclass()` because I needed to check whether the exact class was a dataclass:
```python
def is_dataclass_type(cls: type) -> bool:
try:
return "__dataclass_fields__" in cls.__dict__
except Exception:
return False
```
Changing the CPython behavior might be impossible for compatibility reasons, but in that case, we should document and test this edge case.
cc @ericvsmith @carljm for dataclasses.
### CPython versions tested on:
CPython main branch
### Operating systems tested on:
macOS
</pre>
<hr>
<a href="https://github.com/python/cpython/issues/119260">View on GitHub</a>
<p>Labels: type-bug, stdlib</p>
<p>Assignee: </p>