Skip to content

Commit fbc20bb

Browse files
vidit2606vidit bhargava
and
vidit bhargava
authored
Make custom annotation generation deterministic (#326)
Co-authored-by: vidit bhargava <[email protected]>
1 parent e242f7f commit fbc20bb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

stone/backends/python_types.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -701,8 +701,10 @@ def _generate_struct_class_custom_annotations(self, ns, data_type):
701701

702702
for field in data_type.fields:
703703
field_name = fmt_var(field.name, check_reserved=True)
704-
for annotation_type, processor in self._generate_custom_annotation_processors(
705-
ns, field.data_type, field.custom_annotations):
704+
recursive_processors = list(self._generate_custom_annotation_processors(
705+
ns, field.data_type, field.custom_annotations))
706+
recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name)
707+
for annotation_type, processor in recursive_processors:
706708
annotation_class = class_name_for_annotation_type(annotation_type, ns)
707709
self.emit('if annotation_type is {}:'.format(annotation_class))
708710
with self.indent():
@@ -991,6 +993,8 @@ def _generate_union_class_custom_annotations(self, ns, data_type):
991993
if len(recursive_processors) == 0:
992994
continue
993995

996+
recursive_processors = sorted(recursive_processors, key=lambda x: x[0].name)
997+
994998
field_name = fmt_func(field.name)
995999
self.emit('if self.is_{}():'.format(field_name))
9961000

stone/cli.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
A command-line interface for StoneAPI.
33
"""
44

5-
import importlib
5+
import importlib.util
6+
import importlib.machinery
67
import io
78
import json
89
import logging

0 commit comments

Comments
 (0)