We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hasattr
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
GitHub fields:
assignee = None closed_at = <Date 2021-10-19.21:32:03.403> created_at = <Date 2021-10-19.21:26:07.224> labels = ['OS-mac', 'type-bug', 'invalid', '3.9'] title = 'checking any object for attr "get" always returns True with `hasattr`' updated_at = <Date 2021-10-19.21:32:03.402> user = 'https://bugs.python.org/mcmassok'
bugs.python.org fields:
activity = <Date 2021-10-19.21:32:03.402> actor = 'ned.deily' assignee = 'none' closed = True closed_date = <Date 2021-10-19.21:32:03.403> closer = 'ned.deily' components = ['macOS'] creation = <Date 2021-10-19.21:26:07.224> creator = 'm.c.massok' dependencies = [] files = ['50371'] hgrepos = [] issue_num = 45529 keywords = [] message_count = 2.0 messages = ['404353', '404355'] nosy_count = 3.0 nosy_names = ['ronaldoussoren', 'ned.deily', 'm.c.massok'] pr_nums = [] priority = 'normal' resolution = 'not a bug' stage = 'resolved' status = 'closed' superseder = None type = 'behavior' url = 'https://bugs.python.org/issue45529' versions = ['Python 3.9']
The text was updated successfully, but these errors were encountered:
Any time you use hasattr to check if a dict has the attr "get", it returns true.
Uploaded .py file has bug example.
.py
Sorry, something went wrong.
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
No branches or pull requests
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: