canmatrix icon indicating copy to clipboard operation
canmatrix copied to clipboard

Support os.fspath protocol

Open altendky opened this issue 6 years ago • 0 comments

Traceback (most recent call last):
  File "/home/epc/g/34/st/sub/epyqlib/epyqlib/nvview.py", line 321, in write_to_auto_parameters
    builder.load_epp(parameter_source_path, can_path=sym)
  File "/home/epc/g/34/st/sub/epyqlib/epyqlib/autodevice/build.py", line 81, in load_epp
    matrix, = canmatrix.formats.loadp(can_path).values()
  File "/home/epc/g/34/st/venv/src/canmatrix/canmatrix/formats.py", line 59, in loadp
    if path.endswith(extension) and "load" in supportedFormats[supportedImportType]:
AttributeError: 'PosixPath' object has no attribute 'endswith'

https://docs.python.org/3/library/os.html#os.fspath (note both os.fspath() and os.PathLike)

I'm not sure the proper idiom for handling this in a polyglot way (anything less than 3.6 in this case), but it would be nice moving forward.

Maybe in a utils module there would be:

def fspath(path):
    if sys.version < (3, 6):
        return path

    return os.fspath(path)

altendky avatar Jun 21 '18 20:06 altendky