Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions typesafety/test_upath_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,103 @@

p = {{ cls }}(".", {{ supported_example_name }}={{ unsupported_example_value }}) # ER: Argument "{{ supported_example_name }}" to "{{ cls }}" has incompatible type.*

- case: upath_constructor_sopts_via_dict
disable_cache: false
parametrized:
- module: upath.implementations.cached
cls: SimpleCachePath
- module: upath.implementations.cloud
cls: GCSPath
- module: upath.implementations.cloud
cls: S3Path
- module: upath.implementations.cloud
cls: AzurePath
- module: upath.implementations.data
cls: DataPath
- module: upath.implementations.github
cls: GitHubPath
- module: upath.implementations.hdfs
cls: HDFSPath
- module: upath.implementations.http
cls: HTTPPath
- module: upath.implementations.local
cls: FilePath
- module: upath.implementations.memory
cls: MemoryPath
- module: upath.implementations.sftp
cls: SFTPPath
- module: upath.implementations.smb
cls: SMBPath
- module: upath.implementations.tar
cls: TarPath
- module: upath.implementations.webdav
cls: WebdavPath
- module: upath.implementations.zip
cls: ZipPath
main: |
from typing import Any
from {{ module }} import {{ cls }}

kw: dict[str, Any] = {}
p = {{ cls }}(".", **kw)
reveal_type(p) # N: Revealed type is "{{ module }}.{{ cls }}"

- case: upath_constructor_sopts_via_typed_dict
disable_cache: false
parametrized:
- module: upath.implementations.cached
cls: SimpleCachePath
td: SimpleCacheStorageOptions
- module: upath.implementations.cloud
cls: GCSPath
td: GCSStorageOptions
- module: upath.implementations.cloud
cls: S3Path
td: S3StorageOptions
- module: upath.implementations.cloud
cls: AzurePath
td: AzureStorageOptions
- module: upath.implementations.data
cls: DataPath
td: DataStorageOptions
- module: upath.implementations.github
cls: GitHubPath
td: GitHubStorageOptions
- module: upath.implementations.hdfs
cls: HDFSPath
td: HDFSStorageOptions
- module: upath.implementations.http
cls: HTTPPath
td: HTTPStorageOptions
- module: upath.implementations.local
cls: FilePath
td: FileStorageOptions
- module: upath.implementations.memory
cls: MemoryPath
td: MemoryStorageOptions
- module: upath.implementations.sftp
cls: SFTPPath
td: SFTPStorageOptions
- module: upath.implementations.smb
cls: SMBPath
td: SMBStorageOptions
- module: upath.implementations.tar
cls: TarPath
td: TarStorageOptions
- module: upath.implementations.webdav
cls: WebdavPath
td: WebdavStorageOptions
- module: upath.implementations.zip
cls: ZipPath
td: ZipStorageOptions
main: |
from {{ module }} import {{ cls }}
from upath.types.storage_options import {{ td }}

kw: {{ td }} = {{ td }}()
p = {{ cls }}(".", **kw)
reveal_type(p) # N: Revealed type is "{{ module }}.{{ cls }}"

# FIXME: mypy emits a 'defined here' note when emitting the error below.
# seems to be a limitation/bug in pytest-mypy-plugins that I can't match it
#
Expand Down
54 changes: 18 additions & 36 deletions upath/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,120 +473,105 @@ def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["simplecache"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.cached.SimpleCachePath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["gcs", "gs"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.cloud.GCSPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["s3", "s3a"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.cloud.S3Path: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["az", "abfs", "abfss", "adl"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.cloud.AzurePath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["data"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.data.DataPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["github"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.github.GitHubPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["hdfs"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.hdfs.HDFSPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["http", "https"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.http.HTTPPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["file", "local"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.local.FilePath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["memory"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.memory.MemoryPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["sftp", "ssh"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.sftp.SFTPPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["smb"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.smb.SMBPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["tar"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.tar.TarPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["webdav"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.webdav.WebdavPath: ...
@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal["zip"],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.zip.ZipPath: ...

if sys.platform == "win32":
Expand All @@ -596,8 +581,7 @@ def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal[""],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.local.WindowsUPath: ...

else:
Expand All @@ -607,17 +591,15 @@ def __new__(
cls,
*args: JoinablePathLike,
protocol: Literal[""],
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> _uimpl.local.PosixUPath: ...

@overload # noqa: E301
def __new__(
cls,
*args: JoinablePathLike,
protocol: str | None = ...,
chain_parser: FSSpecChainParser = ...,
**storage_options: Any,
**_: Any,
) -> Self: ...

def __new__(
Expand Down
2 changes: 0 additions & 2 deletions upath/extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ def _chain(self):
protocol=self.__wrapped__.protocol,
storage_options=dict(self.__wrapped__.storage_options),
),
[],
[],
)

# === wrapped interface ===========================================
Expand Down
4 changes: 2 additions & 2 deletions upath/implementations/cloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from typing_extensions import Unpack

from upath._chain import FSSpecChainParser
from upath.types.storage_options import AzureBlobStorageOptions
from upath.types.storage_options import AzureStorageOptions
from upath.types.storage_options import GCSStorageOptions
from upath.types.storage_options import S3StorageOptions

Expand Down Expand Up @@ -150,7 +150,7 @@ def __init__(
*args: JoinablePathLike,
protocol: Literal["abfs", "abfss", "adl", "az"] | None = None,
chain_parser: FSSpecChainParser = DEFAULT_CHAIN_PARSER,
**storage_options: Unpack[AzureBlobStorageOptions],
**storage_options: Unpack[AzureStorageOptions],
) -> None:
super().__init__(
*args, protocol=protocol, chain_parser=chain_parser, **storage_options
Expand Down
4 changes: 2 additions & 2 deletions upath/implementations/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from typing_extensions import Unpack

from upath._chain import FSSpecChainParser
from upath.types.storage_options import GithubStorageOptions
from upath.types.storage_options import GitHubStorageOptions

__all__ = ["GitHubPath"]

Expand All @@ -42,7 +42,7 @@ def __init__(
*args: JoinablePathLike,
protocol: Literal["github"] | None = ...,
chain_parser: FSSpecChainParser = ...,
**storage_options: Unpack[GithubStorageOptions],
**storage_options: Unpack[GitHubStorageOptions],
) -> None: ...

@property
Expand Down
8 changes: 4 additions & 4 deletions upath/types/storage_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"SimpleCacheStorageOptions",
"GCSStorageOptions",
"S3StorageOptions",
"AzureBlobStorageOptions",
"AzureStorageOptions",
"DataStorageOptions",
"GithubStorageOptions",
"GitHubStorageOptions",
"HDFSStorageOptions",
"HTTPStorageOptions",
"FileStorageOptions",
Expand Down Expand Up @@ -142,7 +142,7 @@ class S3StorageOptions(_AbstractStorageOptions, total=False):
cache_regions: bool


class AzureBlobStorageOptions(_AbstractStorageOptions, total=False):
class AzureStorageOptions(_AbstractStorageOptions, total=False):
"""Storage options for Azure Blob Storage and Azure Data Lake Gen2"""

# Account and authentication
Expand Down Expand Up @@ -188,7 +188,7 @@ class DataStorageOptions(_AbstractStorageOptions, total=False):
# No specific options for Data URIs at the moment


class GithubStorageOptions(_AbstractStorageOptions, total=False):
class GitHubStorageOptions(_AbstractStorageOptions, total=False):
"""Storage options for GitHub repository filesystem"""

# Repository identification
Expand Down