fsspec / universal_pathlib

pathlib api extended to use fsspec backends
MIT License
251 stars 44 forks source link

Add type annotations to UPath #50

Closed normanrz closed 2 years ago

normanrz commented 2 years ago

We use UPath in a project with mypy typing. Most functions and attributes are inferred properly, even without type annotations in upath. However, we had to create a stub to teach mypy the subclass relationship with pathlib.Path and declare fs and _kwargs attributes in a stub file (see below). Perhaps it would be easier for other users, if upath shipped with these stub file or has type annotations directly in the code. I'd be happy to help with a PR.

./stubs/upath/__init__.py:

from pathlib import Path
from typing import Any, Dict

import fsspec

class UPath(Path):
    fs: fsspec.AbstractFileSystem
    _kwargs: Dict[str, Any]