Skip to content

Commit

Permalink
Merge pull request #300 from Carreau/dont-import-network
Browse files Browse the repository at this point in the history
Don't trigger autoimport on network requests.
  • Loading branch information
Carreau authored Feb 13, 2024
2 parents a13a5bd + 010573e commit 5609491
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/python/pyflyby/_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -1914,8 +1914,27 @@ def ofind_with_autoimport(oname, namespaces=None):
is_multiline = len(ip.buffer) > 0
if namespaces is None:
namespaces = _ipython_namespaces(ip)
if not is_multiline and is_identifier(oname, dotted=True):
self.auto_import(str(oname), [ns for nsname,ns in namespaces][::-1])
is_network_request = False
frame = inspect.currentframe()
# jupyter_lab_completer seem to send inspect request when
# cycling through completions which trigger import.
# We cannot differentiate those from actual inspect when
# clicking on an object.
# So for now when we see the inspect request comes from
# ipykernel, we just don't autoimport
while frame is not None:
if "ipykernel.py" in inspect.getframeinfo(frame).filename:
is_network_request = True
break
frame = frame.f_back
if (
not is_multiline
and is_identifier(oname, dotted=True)
and not is_network_request
):
self.auto_import(
str(oname), [ns for nsname, ns in namespaces][::-1]
)
result = __original__(oname, namespaces=namespaces)
return result
return True
Expand Down

0 comments on commit 5609491

Please sign in to comment.