@@ -7475,12 +7475,16 @@ def name_not_defined(self, name: str, ctx: Context, namespace: str | None = None
74757475 self .record_incomplete_ref ()
74767476 return
74777477 message = f'Name "{ name } " is not defined'
7478- # Collect all names in scope to suggest similar alternatives
7479- alternatives = self ._get_names_in_scope ()
7480- alternatives .discard (name )
7481- matches = best_matches (name , alternatives , n = 3 )
7482- if matches :
7483- message += f"; did you mean { pretty_seq (matches , 'or' )} ?"
7478+ if (
7479+ "." not in name
7480+ and not (name .startswith ("__" ) and name .endswith ("__" ))
7481+ and f"builtins.{ name } " not in SUGGESTED_TEST_FIXTURES
7482+ ):
7483+ alternatives = self ._get_names_in_scope ()
7484+ alternatives .discard (name )
7485+ matches = best_matches (name , alternatives , n = 3 )
7486+ if matches :
7487+ message += f"; did you mean { pretty_seq (matches , 'or' )} ?"
74847488 self .fail (message , ctx , code = codes .NAME_DEFINED )
74857489
74867490 if f"builtins.{ name } " in SUGGESTED_TEST_FIXTURES :
@@ -7532,8 +7536,8 @@ def _get_names_in_scope(self) -> set[str]:
75327536 if not (len (builtin_name ) > 1 and builtin_name [0 ] == "_" and builtin_name [1 ] != "_" ):
75337537 names .add (builtin_name )
75347538
7535- # Filter out internal/dunder names that aren't useful for suggestions and might introduce noise
7536- return {n for n in names if not n .startswith ("__" ) or n . endswith ( "__" ) }
7539+ # Filter out internal/dunder names that aren't useful as suggestions
7540+ return {n for n in names if not n .startswith ("__" )}
75377541
75387542 def already_defined (
75397543 self , name : str , ctx : Context , original_ctx : SymbolTableNode | SymbolNode | None , noun : str
0 commit comments