@@ -362,12 +362,12 @@ def query(self, search_name):
362362 # Sphinx like matching with abbreviated name
363363 pattern = search_name .replace ("." , r"\." )
364364 pattern = pattern .replace ("~" , ".*" )
365- pattern = re .compile (pattern + "$" )
365+ regex = re .compile (pattern + "$" )
366366 # Might be slow, but works for now
367367 matches = {
368368 key : value
369369 for key , value in self .known_imports .items ()
370- if re .match (pattern , key )
370+ if regex .match (key )
371371 }
372372 if len (matches ) > 1 :
373373 shortest_key = sorted (matches .keys (), key = lambda x : len (x ))[0 ]
@@ -383,6 +383,7 @@ def query(self, search_name):
383383 elif len (matches ) == 1 :
384384 annotation_name , known_import = matches .popitem ()
385385 else :
386+ search_name = search_name [2 :]
386387 logger .debug (
387388 "couldn't match %r in %s" , search_name , self .current_source
388389 )
@@ -391,7 +392,8 @@ def query(self, search_name):
391392 # Try scope of current module
392393 try_qualname = f"{ self .current_source .import_path } .{ search_name } "
393394 known_import = self .known_imports .get (try_qualname )
394- annotation_name = search_name
395+ if known_import :
396+ annotation_name = search_name
395397
396398 if known_import is None :
397399 # Try a subset of the qualname (first 'a.b.c', then 'a.b' and 'a')
0 commit comments