This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: checking any object for attr "get" always returns True with `hasattr`
Type: behavior Stage: resolved
Components: macOS Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: m.c.massok, ned.deily, ronaldoussoren
Priority: normal Keywords:

Created on 2021-10-19 21:26 by m.c.massok, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
bug.py m.c.massok, 2021-10-19 21:26
Messages (2)
msg404353 - (view) Author: Clay Massok (m.c.massok) Date: 2021-10-19 21:26
Any time you use `hasattr` to check if a dict has the attr "get", it returns true.

Uploaded `.py` file has bug example.
msg404355 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2021-10-19 21:32
That is expected behavior. "get" is a method of "dict".

>>> payload = {}
>>> dir(payload)
['__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__ior__', '__iter__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__or__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__ror__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'clear', 'copy', 'fromkeys', 'get', 'items', 'keys', 'pop', 'popitem', 'setdefault', 'update', 'values']
>>> hasattr(payload, "keys")
True


https://docs.python.org/3/library/stdtypes.html#dict.get
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89692
2021-10-19 21:32:03ned.deilysetstatus: open -> closed
resolution: not a bug
messages: + msg404355

stage: resolved
2021-10-19 21:26:07m.c.massokcreate