Skip to content

Commit

Permalink
Sort .pyi file in alphabetical order of class names
Browse files Browse the repository at this point in the history
  • Loading branch information
VirxEC committed Jun 24, 2024
1 parent 4a09fc0 commit cb1e914
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions codegen/pyi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ pub fn generator(type_data: &[PythonBindType]) -> io::Result<()> {
("Vec<u8>", "bytes"),
];

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

for item in sorted_types {
let type_name = item.struct_name();

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

if !is_union {
if !(matches!(item, PythonBindType::Union { .. })) {
write_str!(file, " def pack(self) -> bytes: ...");
write_str!(file, " @staticmethod");
write_fmt!(file, " def unpack(data: bytes) -> {type_name}:");
Expand Down

0 comments on commit cb1e914

Please sign in to comment.