New submission from Johan Hidding <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue37868>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com