[New-bugs-announce] [issue37868] `is_dataclass` returns `True` if `getattr` always succeeds.

Johan Hidding report at bugs.python.org
Thu Aug 15 08:02:15 EDT 2019


New submission from Johan Hidding <johannes.hidding at gmail.com>:

Given a class `A` that overloads `__getattr__`

```
class A:
  def __getattr__(self, key):
    return 0
```

An instance of this class is always identified as a dataclass.

```
from dataclasses import is_dataclass

a = A()
print(is_dataclass(a))
```

gives the output `True`.

Possible fix: check for the instance type.

```
is_dataclass(type(a))
```

does give the correct answer.

----------
components: Library (Lib)
messages: 349802
nosy: Johan Hidding
priority: normal
severity: normal
status: open
title: `is_dataclass` returns `True` if `getattr` always succeeds.
type: behavior
versions: Python 3.7

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue37868>
_______________________________________


More information about the New-bugs-announce mailing list