@@ -10,9 +10,8 @@ class alongside the canonical `ErrorType(StrEnum)`. This script removes the dupl
1010 rewires references to use `ErrorType`.
1111- Missing @docs_group decorator: Adds `@docs_group('Models')` to all model classes for API
1212 reference documentation grouping, along with the required import.
13- - Class sorting: Sorts class definitions alphabetically (with topological ordering to respect
14- inheritance dependencies), so that regeneration from a reordered OpenAPI spec produces
15- minimal diffs.
13+ - Class sorting: Sorts class definitions alphabetically (with topological ordering to respect inheritance
14+ dependencies), so that regeneration from a reordered OpenAPI spec produces minimal diffs.
1615"""
1716
1817from __future__ import annotations
@@ -62,8 +61,7 @@ def deduplicate_error_type_enum(content: str) -> str:
6261def add_docs_group_decorators (content : str ) -> str :
6362 """Add `@docs_group('Models')` decorator to all model classes and the required import.
6463
65- This function is idempotent — it skips the import and decorators if they
66- already exist.
64+ This function is idempotent — it skips the import and decorators if they already exist.
6765 """
6866 # Add the import after the existing imports (only if not already present).
6967 if 'from apify_client._docs import docs_group' not in content :
@@ -85,15 +83,12 @@ def add_docs_group_decorators(content: str) -> str:
8583def sort_classes (content : str ) -> str :
8684 """Sort class definitions alphabetically while respecting inheritance order.
8785
88- Uses topological sorting so that base classes always appear before their
89- subclasses, with alphabetical ordering as the tie-breaker. This makes the
90- output deterministic regardless of the order in the OpenAPI spec, which
91- keeps diffs minimal across regenerations.
86+ Uses topological sorting so that base classes always appear before their subclasses, with alphabetical ordering as
87+ the tie-breaker. This makes the output deterministic regardless of the order in the OpenAPI spec, which keeps diffs
88+ minimal across regenerations.
9289
93- Only the class statement's base-class expression creates an ordering
94- constraint — field type annotations are lazy strings thanks to
95- ``from __future__ import annotations`` and don't require forward
96- declaration.
90+ Only the class statement's base-class expression creates an ordering constraint — field type annotations are lazy
91+ strings thanks to `from __future__ import annotations` and don't require forward declaration.
9792 """
9893 lines = content .split ('\n ' )
9994
@@ -111,7 +106,7 @@ def sort_classes(content: str) -> str:
111106 header = '\n ' .join (header_lines )
112107
113108 # Split the remainder into class blocks.
114- # Each block starts with `` @docs_group('Models')` ` on its own line.
109+ # Each block starts with `@docs_group('Models')` on its own line.
115110 rest = '\n ' .join (lines [header_end :])
116111 decorator_escaped = re .escape (DOCS_GROUP_DECORATOR )
117112 raw_blocks = re .split (rf'(?=^{ decorator_escaped } $)' , rest , flags = re .MULTILINE )
@@ -127,6 +122,7 @@ def sort_classes(content: str) -> str:
127122 continue
128123 class_name = match .group (1 )
129124 base_expr = match .group (2 )
125+
130126 # Collect all capitalized identifiers from the base-class expression.
131127 referenced = set (re .findall (r'\b([A-Z]\w+)\b' , base_expr ))
132128 class_blocks [class_name ] = block
0 commit comments