Skip to content

Commit cb1e914

Browse files
committed
Sort .pyi file in alphabetical order of class names
1 parent 4a09fc0 commit cb1e914

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

codegen/pyi.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
4040
("Vec<u8>", "bytes"),
4141
];
4242

43-
for item in type_data {
44-
let is_union = matches!(item, PythonBindType::Union { .. });
43+
let mut sorted_types: Vec<&PythonBindType> = type_data.iter().collect();
44+
sorted_types.sort_by(|a, b| a.struct_name().cmp(b.struct_name()));
4545

46+
for item in sorted_types {
4647
let type_name = item.struct_name();
4748

4849
write_fmt!(file, "class {type_name}:");
@@ -217,7 +218,7 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
217218
write_str!(file, " def __repr__(self) -> str: ...");
218219
write_str!(file, " def __hash__(self) -> str: ...");
219220

220-
if !is_union {
221+
if !(matches!(item, PythonBindType::Union { .. })) {
221222
write_str!(file, " def pack(self) -> bytes: ...");
222223
write_str!(file, " @staticmethod");
223224
write_fmt!(file, " def unpack(data: bytes) -> {type_name}:");

0 commit comments

Comments
 (0)