Skip to content

Commit

Permalink
Backport PR #14004: Don't do truthy check on object; use is not None
Browse files Browse the repository at this point in the history
  • Loading branch information
Carreau committed Apr 25, 2023
1 parent 41c5449 commit e5d97fb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion IPython/core/oinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def info(self, obj, oname="", info=None, detail_level=0) -> Dict[str, Any]:
att_name = oname.split(".")[-1]
parents_docs = None
prelude = ""
if info and info.parent and hasattr(info.parent, HOOK_NAME):
if info and info.parent is not None and hasattr(info.parent, HOOK_NAME):
parents_docs_dict = getattr(info.parent, HOOK_NAME)
parents_docs = parents_docs_dict.get(att_name, None)
out = dict(
Expand Down
17 changes: 17 additions & 0 deletions IPython/core/tests/test_oinspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,23 @@ def cleanup_user_ns(**kwargs):
del ip.user_ns[k]


def test_pinfo_bool_raise():
"""
Test that bool method is not called on parent.
"""

class RaiseBool:
attr = None

def __bool__(self):
raise ValueError("pinfo should not access this method")

raise_bool = RaiseBool()

with cleanup_user_ns(raise_bool=raise_bool):
ip._inspect("pinfo", "raise_bool.attr", detail_level=0)


def test_pinfo_getindex():
def dummy():
"""
Expand Down

0 comments on commit e5d97fb

Please sign in to comment.