Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions objgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -582,9 +582,14 @@ def at_addrs(address_set):
.. versionadded:: 3.4
"""
res = []
for o in gc.get_objects():
if id(o) in address_set:
res.append(o)
id_to_obj = dict((id(o), o) for o in gc.get_objects())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest

id_to_obj = {id(o): o for o in gc.get_objects()}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


for i in address_set:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest change these lines to

return [
    id_to_obj[i] 
    for i in address_set
    if i in id_to_obj
]

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 except I'd put it all on a single line

if i not in id_to_obj: # ignore non-existing objects.
continue
o = id_to_obj[i]
res.append(o)

return res


Expand Down