BlueBrain / morphoclass

Neuronal morphology preparation and classification using Machine Learning.
https://morphoclass.readthedocs.io
Apache License 2.0
8 stars 4 forks source link

Consider consistently using `types.StrPath` #51

Closed Stannislav closed 2 years ago

Stannislav commented 2 years ago

We often pass paths as function arguments, which leads to following types and structures:

def f(path: str | pathlib.Path):
    path = pathlib.Path(path)
    ...

The constructor of pathlib.Path expects arguments of type str | os.PathLike[str], where os.PathLike is a broad abstract base class. So we can also broaden the type of the function f by writing

def f(path: str | os.PathLike):
    path = pathlib.Path(path)
    ...

There is already an alias for this union defined in morphoclass.types: StrPath, so one just needs to start using it. Then we'd have

def f(path: StrPath):
    path = pathlib.Path(path)
    ...