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

Expose and improve the docstrings of export_od and import_id #473

Merged
33 changes: 20 additions & 13 deletions canopen/objectdictionary/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,25 @@
logger = logging.getLogger(__name__)


def export_od(od, dest: Union[str, TextIO, None] = None, doc_type: Optional[str] = None):
""" Export :class: ObjectDictionary to a file.
def export_od(
od: ObjectDictionary,
dest: Union[str, TextIO, None] = None,
doc_type: Optional[str] = None
) -> None:
"""Export an object dictionary.

:param od:
:class: ObjectDictionary object to be exported
The object dictionary to be exported.
:param dest:
export destination. filename, or file-like object or None.
if None, the document is returned as string
:param doc_type: type of document to export.
If a filename is given for dest, this default to the file extension.
Otherwise, this defaults to "eds"
:rtype: str or None
The export destination as a filename, a file-like object, or ``None``.
If ``None``, the document is written to :data:`sys.stdout`.
:param doc_type:
The type of document to export.
If *dest* is a file-like object or ``None``,
*doc_type* must be explicitly provided.
If *dest* is a filename and its extension is ``".eds"`` or ``".dcf"``,
*doc_type* defaults to that extension (the preceeding dot excluded);
else, it defaults to ``"eds"``.
acolomb marked this conversation as resolved.
Show resolved Hide resolved
erlend-aasland marked this conversation as resolved.
Show resolved Hide resolved
"""

opened_here = False
Expand Down Expand Up @@ -64,10 +71,10 @@ def import_od(
"""Parse an EDS, DCF, or EPF file.

:param source:
Path to object dictionary file or a file like object or an EPF XML tree.

:return:
An Object Dictionary instance.
The path to object dictionary file, a file like object, or an EPF XML tree.
:param node_id:
For EDS and DCF files, the node ID to use.
acolomb marked this conversation as resolved.
Show resolved Hide resolved
For other formats, this parameter is ignored.
"""
if source is None:
return ObjectDictionary()
Expand Down
4 changes: 4 additions & 0 deletions doc/od.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ You can access the objects using either index/subindex or names::
API
---

.. autofunction:: canopen.export_od

.. autofunction:: canopen.import_od

.. autoclass:: canopen.ObjectDictionary
:members:

Expand Down
Loading