Skip to content

Commit c6309fd

Browse files
committed
add docstrings to the .pyi
Pylance finds these and displays them
1 parent bf8da74 commit c6309fd

File tree

4 files changed

+280
-40
lines changed

4 files changed

+280
-40
lines changed

autosar_data.pyi

Lines changed: 238 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
"""
2+
Provides functionality to read, modify and write Autosar arxml files,
3+
both separately and in projects consisting of multiple files.
4+
5+
Classes:
6+
7+
- ArxmlFile
8+
- AutosarModel
9+
- AutosarVersion
10+
- Element
11+
- ElementType
12+
- ValidSubElementInfo
13+
14+
Variables:
15+
16+
- __version__
17+
18+
"""
19+
120
from .autosar_data import *
221
from typing import Dict, List, FrozenSet, Literal, TypeAlias, Tuple, Union
322

@@ -10,50 +29,107 @@ ElementContent: TypeAlias = Union[Element, CharacterData]
1029
VersionSpecification: TypeAlias = Union[AutosarVersion, List[AutosarVersion]]
1130

1231
class ArxmlFile:
32+
"""
33+
Represents a file that is part of an AutosarModel
34+
"""
1335
def __repr__(self) -> str: ...
1436
def __str__(self) -> str: ...
1537
filename: str
38+
"""filename of the arxml file. Must be unique within the model."""
1639
version: AutosarVersion
17-
def check_version_compatibility(self, version: AutosarVersion) -> List[IncompatibleItemError]: ...
40+
"""Autosar version of the file"""
41+
def check_version_compatibility(self, version: AutosarVersion) -> List[IncompatibleItemError]:
42+
"""
43+
check if the elements in the file would be compatible with the given target version.
44+
45+
returns a list of compatibility errors, each of which is an IncompatibleElementError, IncompatibleAttributeError or IncompatibleAttributeValueError
46+
"""
47+
...
1848
model: AutosarModel
49+
"""the autosar data model which this file is part of"""
1950
elements_dfs: ArxmlFileElementsDfsIterator
20-
def serialize(self) -> str: ...
51+
"""dfs iterator over all elements in this file"""
52+
def serialize(self) -> str:
53+
"""serialize the the file to a string. This string can be loaded as valid arxml if is written to disk."""
54+
...
2155
xml_standalone: bool
56+
"""contains the xml standalone attribute (if any) in the xml file header"""
2257

2358
class ArxmlFileElementsDfsIterator:
59+
"""
60+
A depth first search iterator over all elements contained in the file that created this iterator
61+
"""
2462
def __iter__(self) -> ArxmlFileElementsDfsIterator: ...
2563
def __next__(self) -> Tuple[int, Element]: ...
2664

2765
class Attribute:
66+
"""
67+
An attribute on an element
68+
"""
2869
attrname: AttributeName
70+
"""name of this attribute"""
2971
content: CharacterData
72+
"""content of the attribute - this data can be free-form text, a pre-defined enum value (str), or very rarely a float or int"""
3073

3174
class AttributeIterator:
75+
"""
76+
Iterates over all attributes on an element
77+
"""
3278
def __iter__(self) -> AttributeIterator: ...
3379
def __next__(self) -> Attribute : ...
3480

3581
class AutosarDataError(Exception):
3682
pass
3783

3884
class AutosarModel:
85+
"""
86+
Autosar data model. It contains all elements.
87+
"""
3988
def __repr__(self) -> str: ...
4089
def __str__(self) -> str: ...
41-
def create_file(self, filename: str, version: AutosarVersion) -> ArxmlFile: ...
42-
def load_buffer(self, buffer: str, filename: str, strict: bool) -> Tuple[ArxmlFile, List[str]]: ...
43-
def load_file(self, filename: str, strict: bool) -> Tuple[ArxmlFile, List[str]]: ...
44-
def remove_file(self, arxmlfile: ArxmlFile) -> None: ...
45-
def serialize_files(self) -> Dict[str, str]: ...
46-
def write(self) -> None: ...
90+
def create_file(self, filename: str, version: AutosarVersion) -> ArxmlFile:
91+
"""create a new file in the model"""
92+
...
93+
def load_buffer(self, buffer: str, filename: str, strict: bool) -> Tuple[ArxmlFile, List[str]]:
94+
"""load a buffer (string) as arxml"""
95+
...
96+
def load_file(self, filename: str, strict: bool) -> Tuple[ArxmlFile, List[str]]:
97+
"""load a file as arxml"""
98+
...
99+
def remove_file(self, arxmlfile: ArxmlFile) -> None:
100+
"""remove a file from the model. Any elements belonging exclusively to that file will also be removed."""
101+
...
102+
def serialize_files(self) -> Dict[str, str]:
103+
"""serialize all files individually, to generate a dict(filename, serialized content),"""
104+
...
105+
def write(self) -> None:
106+
"""write all files in the model to disk"""
107+
...
47108
files: List[ArxmlFile]
109+
"""a list of ArxmlFile objects containing all files in the model"""
48110
root_element: Element
49-
def get_element_by_path(self, autosar_path: str) -> Element: ...
111+
"""The root element of the model, <AUTOSAR>"""
112+
def get_element_by_path(self, autosar_path: str) -> Element:
113+
"""get an identifiable element in the model by its Autosar path"""
114+
...
50115
elements_dfs: ElementsDfsIterator
51-
def sort(self) -> None: ...
116+
"""depth first dearch iterator over all elements in the model, regardless of their association with a file"""
117+
def sort(self) -> None:
118+
"""sort the entire model in place. Takes all ordering constraints into account."""
119+
...
52120
identifiable_elements: List[str]
53-
def get_references_to(self, target_path: str) -> List[Element]: ...
54-
def check_references(self) -> List[Element]: ...
121+
"""List of all paths of identifiable elements in the model"""
122+
def get_references_to(self, target_path: str) -> List[Element]:
123+
"""get all reference elements which refer to the given Autosar path"""
124+
...
125+
def check_references(self) -> List[Element]:
126+
"""check all references in the model and return a list of elements containing invalid references"""
127+
...
55128

56129
class AutosarVersion:
130+
"""
131+
A version of the Autosar standard
132+
"""
57133
def __new__(cls, verstring: str) -> AutosarVersion: ...
58134
# this is the stupid result of method used by PyO3 to translate Rust enums
59135
Autosar_4_0_1: AutosarVersion
@@ -77,102 +153,226 @@ class AutosarVersion:
77153
Autosar_00051: AutosarVersion
78154

79155
class ContentType:
156+
"""
157+
The content type of an element
158+
"""
80159
# this is the stupid result of method used by PyO3 to translate Rust enums
81160
Elements: ContentType
82161
CharacterData: ContentType
83162
Mixed: ContentType
84163

85164
class Element:
165+
"""
166+
An element in the Autosar data model
167+
"""
86168
def __repr__(self) -> str: ...
87169
def __str__(self) -> str: ...
88170
def serialize(self) -> str: ...
89171
parent: Element
172+
"""reference to the parent of this element"""
90173
element_name: ElementName
174+
"""ElementName of this element, e.g. AUTOSAR or AR-PACKAGE"""
91175
element_type: ElementType
176+
"""Reference to the element type of the element in the specification"""
92177
item_name: str
178+
"""item name of an identifiable element, or None for elements which are not identifiable.
179+
180+
Setting this value renames the element and updates all references to it.
181+
"""
93182
is_identifiable: bool
183+
"""true if the element is identifiable, false otherwise"""
94184
is_reference: bool
185+
"""true if the element can contain a reference to another element"""
95186
path: str
187+
"""the full autosar path of an identifiable element"""
96188
model: AutosarModel
189+
"""reference to the model containing this element"""
97190
content_type: ContentType
98-
def create_sub_element(self, element_name: ElementName) -> Element: ...
99-
def create_sub_element_at(self, element_name: ElementName, position: int) -> Element: ...
100-
def create_named_sub_element(self, element_name: ElementName, item_name: str) -> Element: ...
101-
def create_named_sub_element_at(self, element_name: ElementName, item_name: str, position: int) -> Element: ...
102-
def create_copied_sub_element(self, other: Element) -> Element: ...
103-
def create_copied_sub_element_at(self, other: Element, position: int) -> Element: ...
104-
def move_element_here(self, move_element: Element) -> Element: ...
105-
def move_element_here_at(self, move_element: Element, position: int) -> Element: ...
106-
def remove_sub_element(self, element: Element) -> None: ...
191+
"""content type of the element: character data (<X>some text</X>), elements (<X><Y></Y></X>), or Mixed"""
192+
def create_sub_element(self, element_name: ElementName) -> Element:
193+
"""create a sub element under this element with the given ElementName"""
194+
...
195+
def create_sub_element_at(self, element_name: ElementName, position: int) -> Element:
196+
"""create a sub element under this element with the given ElementName at a specific position"""
197+
...
198+
def create_named_sub_element(self, element_name: ElementName, item_name: str) -> Element:
199+
"""create a named sub element under this element with the given ElementName"""
200+
...
201+
def create_named_sub_element_at(self, element_name: ElementName, item_name: str, position: int) -> Element:
202+
"""create a named sub element under this element with the given ElementName at a specific position"""
203+
...
204+
def create_copied_sub_element(self, other: Element) -> Element:
205+
"""create a copy of some other element (with all of its children) as a child of this element"""
206+
...
207+
def create_copied_sub_element_at(self, other: Element, position: int) -> Element:
208+
"""create a copy of some other element (with all of its children) as a child of this element at the given position"""
209+
...
210+
def move_element_here(self, move_element: Element) -> Element:
211+
"""move an element from somewhere else in this model or from another model to become a child element"""
212+
...
213+
def move_element_here_at(self, move_element: Element, position: int) -> Element:
214+
"""move an element from somewhere else in this model or from another model to become a child element at the given position"""
215+
...
216+
def remove_sub_element(self, element: Element) -> None:
217+
"""remove a sub element and all of its content"""
218+
...
107219
reference_target: Element
108-
def get_sub_element(self, name_str: str) -> Element: ...
109-
def get_sub_element_at(self, position: int) -> Element: ...
220+
"""returns the target of the reference, if the element contains a reference"""
221+
def get_sub_element(self, name_str: str) -> Element:
222+
"""get a sub element by its element name. If there are several then this returns the first of them"""
223+
...
224+
def get_sub_element_at(self, position: int) -> Element:
225+
"""get an element by its position among the content of this element"""
226+
...
110227
position: int
228+
"""the position of this element in the content of its parent"""
111229
sub_elements: ElementsIterator
230+
"""an iterator over all sub elements in the content of this element. It skips character data content items"""
112231
elements_dfs: ElementsDfsIterator
232+
"""dpeth first search iterator for this element and all of its sub elements"""
113233
character_data: CharacterData
114-
def remove_character_data(self) -> None: ...
115-
def insert_character_content_item(self, chardata: str, position: int) -> None: ...
116-
def remove_character_content_item(self, position: int) -> None: ...
234+
"""character content of this element, if any. For elements with ContentType=Element, or empty elements this is None"""
235+
def remove_character_data(self) -> None:
236+
"""remove the character data"""
237+
...
238+
def insert_character_content_item(self, chardata: str, position: int) -> None:
239+
"""for elements with ElementType mixed, this allows character data to be inserted at any point in the content of this element"""
240+
...
241+
def remove_character_content_item(self, position: int) -> None:
242+
"""remove one character content item from the given position"""
243+
...
117244
content_item_count: int
245+
"""number of content items (character data and/or sub elements)"""
118246
content: ElementContentIterator
247+
"""iterator over all content of this element"""
119248
attributes: AttributeIterator
120-
def attribute_value(self, attrname: AttributeName) -> CharacterData: ...
121-
def set_attribute(self, attrname: AttributeName, chardata: CharacterData) -> None: ...
122-
def set_attribute_string(self, attrname: AttributeName, value: str) -> None: ...
123-
def remove_attribute(self, attrname: AttributeName) -> None: ...
124-
def sort(self) -> None: ...
125-
def list_valid_sub_elements(self) -> List[ValidSubElementInfo]: ...
249+
"""iterator over all attributes of this element"""
250+
def attribute_value(self, attrname: AttributeName) -> CharacterData:
251+
"""get the attribute value of a specific attribute. Returns None if that attribute is not set"""
252+
...
253+
def set_attribute(self, attrname: AttributeName, chardata: CharacterData) -> None:
254+
"""set the given attribute to the provided value. If the attribute is valid for this element it will be created or modified as needed."""
255+
...
256+
def set_attribute_string(self, attrname: AttributeName, value: str) -> None:
257+
"""like set_attribute, but the input will be converted to the target data type as needed"""
258+
...
259+
def remove_attribute(self, attrname: AttributeName) -> None:
260+
"""remove an attribute from the element"""
261+
...
262+
def sort(self) -> None:
263+
"""sort this element and all of its sub elements"""
264+
...
265+
def list_valid_sub_elements(self) -> List[ValidSubElementInfo]:
266+
"""provide information about valid sub elements as a list of ValidSubElementInfo"""
267+
...
126268
file_membership: Tuple[bool, FrozenSet[ArxmlFile]]
127-
def add_to_file(self, file: ArxmlFile) -> None: ...
128-
def remove_from_file(self, file: ArxmlFile) -> None: ...
269+
"""file membership information: the tuple (is_local, set(ArxmlFile)) tells if there is a restriction to file membership attached to this element, and which files the element is part of"""
270+
def add_to_file(self, file: ArxmlFile) -> None:
271+
"""add the element to a file. if necessary all parent elements of this element also become part of the file"""
272+
...
273+
def remove_from_file(self, file: ArxmlFile) -> None:
274+
"""remove this element from a file. Does not affect parent elements. When an element is no longer part of any file it is deleted."""
275+
...
129276
xml_path: str
277+
"""a path listing all xml elements from the root of the model to the element. This is intended for display. e.g. in error messages"""
130278

131279
class ElementContentIterator:
280+
"""
281+
Iterates over all content in an element
282+
283+
Content items an be sub elements or character data
284+
"""
132285
def __iter__(self) -> ElementContentIterator: ...
133286
def __next__(self) -> ElementContent: ...
134287

135288
class ElementType:
289+
"""
290+
Type of an Element in the specification
291+
"""
136292
is_named: bool
293+
"""Elements of this type must have a SHORT-NAME"""
137294
is_ref: bool
295+
"""elements of this type must contain an autosar path in their character data, and have a DEST attribute"""
138296
is_ordered: bool
297+
"""ordered elements may not be sorted, since the sub element order is semantically meaningful"""
139298
splittable: List[AutosarVersion]
140-
def splittable_in(self, version: AutosarVersion) -> bool: ...
141-
def reference_dest_value(self, target: ElementType) -> EnumItem: ...
142-
def find_sub_element(self, target_name: ElementName, version: VersionSpecification) -> ElementType: ...
299+
"""a list of AutosarVersions in which this element is splittable"""
300+
def splittable_in(self, version: AutosarVersion) -> bool:
301+
"""is this element splittable in a particular AutosarVersion"""
302+
...
303+
def reference_dest_value(self, target: ElementType) -> EnumItem:
304+
"""helper to determine the correct value for the DEST attribute when setting a reference"""
305+
...
306+
def find_sub_element(self, target_name: ElementName, version: VersionSpecification) -> ElementType:
307+
"""find the ElementType of the named sub element in the specification of this ElementType"""
308+
...
143309

144310
class ElementsDfsIterator:
311+
"""
312+
Dpeth first search iterator starting at the element which created the iterator
313+
"""
145314
def __iter__(self) -> ElementsDfsIterator: ...
146315
def __next__(self) -> Tuple[int, Element]: ...
147316

148317
class ElementsIterator:
318+
"""
319+
Iterator over all sub elements of an element
320+
"""
149321
def __iter__(self) -> ElementsIterator: ...
150322
def __next__(self) -> Element: ...
151323

152324
class IncompatibleAttributeError:
325+
"""
326+
Information about an attribute that is incompatible with a given target version
327+
"""
153328
def __repr__(self) -> str: ...
154329
def __str__(self) -> str: ...
155330
element: Element
331+
"""Element which contains the incompatible attribute"""
156332
attribute: AttributeName
333+
"""Incompatible attribute"""
157334
allowed_versions: List[AutosarVersion]
335+
"""list of versions in which the attribute is permitted on this element"""
158336

159337
class IncompatibleAttributeValueError:
338+
"""
339+
Information about an attribute value that is incompatible with a given target version
340+
"""
160341
def __repr__(self) -> str: ...
161342
def __str__(self) -> str: ...
162343
element: Element
344+
"""Element which contains the incompatible attribute value"""
163345
attribute: AttributeName
346+
"""Attribute which contains the invalid value"""
164347
attribute_value: str
348+
"""The incompatible attribute value"""
165349
allowed_versions: List[AutosarVersion]
350+
"""list of versions in which the attribute value is permitted on this attribute"""
166351

167352
class IncompatibleElementError:
353+
"""
354+
Information about an element that is incompatible with a given target version
355+
"""
168356
def __repr__(self) -> str: ...
169357
def __str__(self) -> str: ...
170358
element: Element
359+
"""incompatible element"""
171360
allowed_versions: List[AutosarVersion]
361+
"""list of versions in which this element is compatible"""
172362

173363
class ValidSubElementInfo:
364+
"""
365+
Details about a particular sub element
366+
"""
174367
element_name: str
368+
"""name of the potential sub element"""
175369
is_named: bool
370+
"""is the sub element named, i.e. does it need to be created with create_named_sub_element"""
176371
is_allowed: bool
372+
"""is the sub element currently allowed, given the existing content of the element. Note that some sub elements are mutually exclusive"""
177373

178-
version: str
374+
__version__: str
375+
"""
376+
Version of the running autosar_data module.
377+
It contains a semver string of the form 'x.y.z'
378+
"""

0 commit comments

Comments
 (0)