Skip to content

Commit 950edc0

Browse files
committed
export_od: Accept os.PathLike with robust suffix handling.
Utilize the standard library's os.path.splitext() function to find the file name suffix and treat it case-insensitively.
1 parent ef4ed96 commit 950edc0

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

canopen/objectdictionary/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from __future__ import annotations
66

77
import logging
8+
import os
89
import struct
910
from collections.abc import Collection, Iterator, Mapping, MutableMapping
1011
from typing import Optional, TextIO, Union
@@ -19,7 +20,7 @@
1920

2021
def export_od(
2122
od: ObjectDictionary,
22-
dest: Union[str, TextIO, None] = None,
23+
dest: Union[str, os.PathLike, TextIO, None] = None,
2324
doc_type: Optional[str] = None,
2425
) -> None:
2526
"""Export an object dictionary.
@@ -49,10 +50,11 @@ def export_od(
4950

5051
opened_here: Optional[TextIO] = None
5152
try:
52-
if isinstance(dest, str):
53+
if isinstance(dest, (str, os.PathLike)):
5354
if doc_type is None:
55+
_, suffix = os.path.splitext(os.fspath(dest).lower())
5456
for t in supported_doctypes:
55-
if dest.endswith(f".{t}"):
57+
if suffix == f".{t}":
5658
doc_type = t
5759
break
5860
else:

0 commit comments

Comments
 (0)