Skip to content
This repository was archived by the owner on Mar 26, 2026. It is now read-only.

Commit cb55bec

Browse files
committed
preserve default order
1 parent 4879d53 commit cb55bec

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

gapic/schema/imp.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,15 @@
1616
from typing import Tuple
1717

1818

19-
@dataclasses.dataclass(frozen=True, order=True)
19+
@dataclasses.dataclass(frozen=True)
2020
class Import:
2121
package: Tuple[str, ...]
2222
module: str
2323
alias: str = ""
2424

25+
def __lt__(self, other) -> bool:
26+
return str(self) < str(other)
27+
2528
def __eq__(self, other) -> bool:
2629
return self.package == other.package and self.module == other.module
2730

@@ -30,19 +33,19 @@ def __str__(self) -> str:
3033
# We do this for protobuf generated files (_pb2) and api_core
3134
# internals where type information might be missing or incomplete.
3235
needs_type_ignore = self.module.endswith("_pb2") or "api_core" in self.package
33-
34-
if needs_type_ignore:
36+
if not needs_type_ignore:
37+
# Standard import generation
38+
answer = f"import {self.module}"
39+
if self.package:
40+
answer = f"from {'.'.join(self.package)} {answer}"
41+
if self.alias:
42+
answer += f" as {self.alias}"
43+
return answer
44+
else:
3545
# Use 'import absolute.path as module' syntax to prevent Ruff/isort
3646
# from combining this with other imports. This ensures the
3747
# '# type: ignore' comment remains effective for this specific import.
3848
full_module = ".".join(self.package + (self.module,))
3949
alias = self.alias or self.module
4050
return f"import {full_module} as {alias} # type: ignore"
4151

42-
# Standard import generation
43-
answer = f"import {self.module}"
44-
if self.package:
45-
answer = f"from {'.'.join(self.package)} {answer}"
46-
if self.alias:
47-
answer += f" as {self.alias}"
48-
return answer

0 commit comments

Comments
 (0)