Skip to content

Commit

Permalink
Don't trigger autoimport on network requests. (#300)
Browse files Browse the repository at this point in the history
This should mitigate #296
  • Loading branch information
Shiva Shankar Dhamodharan committed Feb 14, 2024
1 parent 3012d78 commit 3e22f86
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 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 "ipkernel.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
2 changes: 1 addition & 1 deletion lib/python/pyflyby/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@



__version__ = '1.8.6.post2+importfix'
__version__ = '1.8.6.post3+importfix'

0 comments on commit 3e22f86

Please sign in to comment.