@@ -42,8 +42,8 @@ def _get_import_cache(ipython):
4242 import_cache = {}
4343
4444 def _format_alias (alias ):
45- return ("import {0 .name} as {0 .asname}" if alias .asname
46- else "import {0 .name}" ). format ( alias )
45+ return (f "import { alias .name } as { alias .asname } " if alias .asname
46+ else f "import { alias .name } " )
4747
4848 class Visitor (ast .NodeVisitor ):
4949 def visit_Import (self , node ):
@@ -56,7 +56,7 @@ def visit_ImportFrom(self, node):
5656 return
5757 for alias in node .names :
5858 (import_cache .setdefault (alias .asname or alias .name , set ())
59- .add ("from {} {}" . format ( node .module , _format_alias (alias )) ))
59+ .add (f "from { node .module } { _format_alias (alias )} " ))
6060
6161 for _ , _ , entry in (
6262 ipython .history_manager .get_tail (
@@ -120,18 +120,19 @@ def __getattr__(self, name):
120120 self .__ipython , value )
121121 return value
122122 except AttributeError :
123- import_target = "{ }.{}" . format ( self . __name__ , name )
123+ import_target = f" { self . __name__ } .{ name } "
124124 try :
125125 submodule = importlib .import_module (import_target )
126126 except ModuleNotFoundError :
127127 pass
128128 except Exception as exc :
129129 # In theory we should just catch ModuleNotFoundError, but
130130 # ome_types (inaccurately) raises ImportError instead.
131- _report (self .__ipython , "import {} caused {}: {}" .format (
132- import_target , type (exc ).__name__ , exc ))
131+ _report (self .__ipython ,
132+ f"import { import_target } caused { type (exc ).__name__ } : "
133+ f"{ exc } " )
133134 else :
134- _report (self .__ipython , "import {}" . format ( import_target ) )
135+ _report (self .__ipython , f "import { import_target } " )
135136 return _make_submodule_autoimporter_module (
136137 self .__ipython , submodule )
137138 raise # Raise AttributeError without chaining ImportError.
@@ -178,7 +179,7 @@ def __getitem__(self, name):
178179 except AttributeError :
179180 pass
180181 # Find single matching import, if any.
181- imports = self ._import_cache .get (name , {"import {}" . format ( name ) })
182+ imports = self ._import_cache .get (name , {f "import { name } " })
182183 if len (imports ) != 1 :
183184 if len (imports ) > 1 :
184185 _report (self ._ipython ,
0 commit comments