diff --git a/typesafety/test_upath_types.yml b/typesafety/test_upath_types.yml index 754e6316..179307fc 100644 --- a/typesafety/test_upath_types.yml +++ b/typesafety/test_upath_types.yml @@ -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 # diff --git a/upath/core.py b/upath/core.py index a94dd3d3..ce309265 100644 --- a/upath/core.py +++ b/upath/core.py @@ -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": @@ -596,8 +581,7 @@ def __new__( cls, *args: JoinablePathLike, protocol: Literal[""], - chain_parser: FSSpecChainParser = ..., - **storage_options: Any, + **_: Any, ) -> _uimpl.local.WindowsUPath: ... else: @@ -607,8 +591,7 @@ def __new__( cls, *args: JoinablePathLike, protocol: Literal[""], - chain_parser: FSSpecChainParser = ..., - **storage_options: Any, + **_: Any, ) -> _uimpl.local.PosixUPath: ... @overload # noqa: E301 @@ -616,8 +599,7 @@ def __new__( cls, *args: JoinablePathLike, protocol: str | None = ..., - chain_parser: FSSpecChainParser = ..., - **storage_options: Any, + **_: Any, ) -> Self: ... def __new__( diff --git a/upath/extensions.py b/upath/extensions.py index 6e6eeb0a..fabc86a6 100644 --- a/upath/extensions.py +++ b/upath/extensions.py @@ -78,8 +78,6 @@ def _chain(self): protocol=self.__wrapped__.protocol, storage_options=dict(self.__wrapped__.storage_options), ), - [], - [], ) # === wrapped interface =========================================== diff --git a/upath/implementations/cloud.py b/upath/implementations/cloud.py index c1bd889f..b62e7bc0 100644 --- a/upath/implementations/cloud.py +++ b/upath/implementations/cloud.py @@ -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 @@ -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 diff --git a/upath/implementations/github.py b/upath/implementations/github.py index d72905a1..f8e47706 100644 --- a/upath/implementations/github.py +++ b/upath/implementations/github.py @@ -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"] @@ -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 diff --git a/upath/types/storage_options.py b/upath/types/storage_options.py index 8ff25283..1dfd5aca 100644 --- a/upath/types/storage_options.py +++ b/upath/types/storage_options.py @@ -18,9 +18,9 @@ "SimpleCacheStorageOptions", "GCSStorageOptions", "S3StorageOptions", - "AzureBlobStorageOptions", + "AzureStorageOptions", "DataStorageOptions", - "GithubStorageOptions", + "GitHubStorageOptions", "HDFSStorageOptions", "HTTPStorageOptions", "FileStorageOptions", @@ -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 @@ -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