Skip to content

Commit

Permalink
Make custom annotation generation deterministic
Browse files Browse the repository at this point in the history
  • Loading branch information
vidit bhargava committed Mar 27, 2024
1 parent e242f7f commit a4dff04
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions stone/backends/python_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,8 +701,10 @@ def _generate_struct_class_custom_annotations(self, ns, data_type):

for field in data_type.fields:
field_name = fmt_var(field.name, check_reserved=True)
for annotation_type, processor in self._generate_custom_annotation_processors(
ns, field.data_type, field.custom_annotations):
recursive_processors = list(self._generate_custom_annotation_processors(
ns, field.data_type, field.custom_annotations))
recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name)
for annotation_type, processor in recursive_processors:
annotation_class = class_name_for_annotation_type(annotation_type, ns)
self.emit('if annotation_type is {}:'.format(annotation_class))
with self.indent():
Expand Down Expand Up @@ -991,6 +993,8 @@ def _generate_union_class_custom_annotations(self, ns, data_type):
if len(recursive_processors) == 0:
continue

recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name)

field_name = fmt_func(field.name)
self.emit('if self.is_{}():'.format(field_name))

Expand Down
3 changes: 2 additions & 1 deletion stone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
A command-line interface for StoneAPI.
"""

import importlib
import importlib.util
import importlib.machinery

Check warning on line 6 in stone/cli.py

View check run for this annotation

Codecov / codecov/patch

stone/cli.py#L5-L6

Added lines #L5 - L6 were not covered by tests
import io
import json
import logging
Expand Down

0 comments on commit a4dff04

Please sign in to comment.