This repository was archived by the owner on Mar 26, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +20
-6
lines changed
Expand file tree Collapse file tree 1 file changed +20
-6
lines changed Original file line number Diff line number Diff line change @@ -26,11 +26,25 @@ def __eq__(self, other) -> bool:
2626 return self .package == other .package and self .module == other .module
2727
2828 def __str__ (self ) -> str :
29- answer = f"import { self .module } "
29+ # Determine if we need to suppress type checking for this import.
30+ # We do this for protobuf generated files (_pb2) and api_core
31+ # internals where type information might be missing or incomplete.
32+ needs_type_ignore = self .module .endswith ("_pb2" ) or "api_core" in self .package
33+
34+ if needs_type_ignore :
35+ # Use 'import absolute.path as module' syntax to prevent Ruff/isort
36+ # from combining this with other imports. This ensures the
37+ # '# type: ignore' comment remains effective for this specific import.
38+ full_module = "." .join (self .package + (self .module ,))
39+ alias = self .alias or self .module
40+ return f"import { full_module } as { alias } # type: ignore"
41+
42+ # Standard import generation
43+ import_clause = f"import { self .module } "
3044 if self .package :
31- answer = f"from { '.' .join (self .package )} { answer } "
45+ import_clause = f"from { '.' .join (self .package )} { import_clause } "
46+
3247 if self .alias :
33- answer += f" as { self .alias } "
34- if self .module .endswith ("_pb2" ) or "api_core" in self .package :
35- answer += " # type: ignore"
36- return answer
48+ import_clause += f" as { self .alias } "
49+
50+ return import_clause
You can’t perform that action at this time.
0 commit comments