Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make custom annotation generation deterministic #326

Merged
merged 1 commit into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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