Skip to content

Commit 57f6a54

Browse files
authored
upath.core: remove chain_parser from overloads for upath class narrowing (#436)
* upath.core: remove chain_parser from overloads for upath class narrowing * upath.extensions.ProxyUPath: fix _chain fallback * upath.types.storage_options: adjust to be in line with path naming * typesafety: add more typechecks for **kwargs * upath.core: update zip and tar typing overload * typesafety: add missing tests
1 parent 6f629c2 commit 57f6a54

File tree

6 files changed

+123
-46
lines changed

6 files changed

+123
-46
lines changed

typesafety/test_upath_types.yml

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,103 @@
291291
292292
p = {{ cls }}(".", {{ supported_example_name }}={{ unsupported_example_value }}) # ER: Argument "{{ supported_example_name }}" to "{{ cls }}" has incompatible type.*
293293
294+
- case: upath_constructor_sopts_via_dict
295+
disable_cache: false
296+
parametrized:
297+
- module: upath.implementations.cached
298+
cls: SimpleCachePath
299+
- module: upath.implementations.cloud
300+
cls: GCSPath
301+
- module: upath.implementations.cloud
302+
cls: S3Path
303+
- module: upath.implementations.cloud
304+
cls: AzurePath
305+
- module: upath.implementations.data
306+
cls: DataPath
307+
- module: upath.implementations.github
308+
cls: GitHubPath
309+
- module: upath.implementations.hdfs
310+
cls: HDFSPath
311+
- module: upath.implementations.http
312+
cls: HTTPPath
313+
- module: upath.implementations.local
314+
cls: FilePath
315+
- module: upath.implementations.memory
316+
cls: MemoryPath
317+
- module: upath.implementations.sftp
318+
cls: SFTPPath
319+
- module: upath.implementations.smb
320+
cls: SMBPath
321+
- module: upath.implementations.tar
322+
cls: TarPath
323+
- module: upath.implementations.webdav
324+
cls: WebdavPath
325+
- module: upath.implementations.zip
326+
cls: ZipPath
327+
main: |
328+
from typing import Any
329+
from {{ module }} import {{ cls }}
330+
331+
kw: dict[str, Any] = {}
332+
p = {{ cls }}(".", **kw)
333+
reveal_type(p) # N: Revealed type is "{{ module }}.{{ cls }}"
334+
335+
- case: upath_constructor_sopts_via_typed_dict
336+
disable_cache: false
337+
parametrized:
338+
- module: upath.implementations.cached
339+
cls: SimpleCachePath
340+
td: SimpleCacheStorageOptions
341+
- module: upath.implementations.cloud
342+
cls: GCSPath
343+
td: GCSStorageOptions
344+
- module: upath.implementations.cloud
345+
cls: S3Path
346+
td: S3StorageOptions
347+
- module: upath.implementations.cloud
348+
cls: AzurePath
349+
td: AzureStorageOptions
350+
- module: upath.implementations.data
351+
cls: DataPath
352+
td: DataStorageOptions
353+
- module: upath.implementations.github
354+
cls: GitHubPath
355+
td: GitHubStorageOptions
356+
- module: upath.implementations.hdfs
357+
cls: HDFSPath
358+
td: HDFSStorageOptions
359+
- module: upath.implementations.http
360+
cls: HTTPPath
361+
td: HTTPStorageOptions
362+
- module: upath.implementations.local
363+
cls: FilePath
364+
td: FileStorageOptions
365+
- module: upath.implementations.memory
366+
cls: MemoryPath
367+
td: MemoryStorageOptions
368+
- module: upath.implementations.sftp
369+
cls: SFTPPath
370+
td: SFTPStorageOptions
371+
- module: upath.implementations.smb
372+
cls: SMBPath
373+
td: SMBStorageOptions
374+
- module: upath.implementations.tar
375+
cls: TarPath
376+
td: TarStorageOptions
377+
- module: upath.implementations.webdav
378+
cls: WebdavPath
379+
td: WebdavStorageOptions
380+
- module: upath.implementations.zip
381+
cls: ZipPath
382+
td: ZipStorageOptions
383+
main: |
384+
from {{ module }} import {{ cls }}
385+
from upath.types.storage_options import {{ td }}
386+
387+
kw: {{ td }} = {{ td }}()
388+
p = {{ cls }}(".", **kw)
389+
reveal_type(p) # N: Revealed type is "{{ module }}.{{ cls }}"
390+
294391
# FIXME: mypy emits a 'defined here' note when emitting the error below.
295392
# seems to be a limitation/bug in pytest-mypy-plugins that I can't match it
296393
#

upath/core.py

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -473,120 +473,105 @@ def __new__(
473473
cls,
474474
*args: JoinablePathLike,
475475
protocol: Literal["simplecache"],
476-
chain_parser: FSSpecChainParser = ...,
477-
**storage_options: Any,
476+
**_: Any,
478477
) -> _uimpl.cached.SimpleCachePath: ...
479478
@overload # noqa: E301
480479
def __new__(
481480
cls,
482481
*args: JoinablePathLike,
483482
protocol: Literal["gcs", "gs"],
484-
chain_parser: FSSpecChainParser = ...,
485-
**storage_options: Any,
483+
**_: Any,
486484
) -> _uimpl.cloud.GCSPath: ...
487485
@overload # noqa: E301
488486
def __new__(
489487
cls,
490488
*args: JoinablePathLike,
491489
protocol: Literal["s3", "s3a"],
492-
chain_parser: FSSpecChainParser = ...,
493-
**storage_options: Any,
490+
**_: Any,
494491
) -> _uimpl.cloud.S3Path: ...
495492
@overload # noqa: E301
496493
def __new__(
497494
cls,
498495
*args: JoinablePathLike,
499496
protocol: Literal["az", "abfs", "abfss", "adl"],
500-
chain_parser: FSSpecChainParser = ...,
501-
**storage_options: Any,
497+
**_: Any,
502498
) -> _uimpl.cloud.AzurePath: ...
503499
@overload # noqa: E301
504500
def __new__(
505501
cls,
506502
*args: JoinablePathLike,
507503
protocol: Literal["data"],
508-
chain_parser: FSSpecChainParser = ...,
509-
**storage_options: Any,
504+
**_: Any,
510505
) -> _uimpl.data.DataPath: ...
511506
@overload # noqa: E301
512507
def __new__(
513508
cls,
514509
*args: JoinablePathLike,
515510
protocol: Literal["github"],
516-
chain_parser: FSSpecChainParser = ...,
517-
**storage_options: Any,
511+
**_: Any,
518512
) -> _uimpl.github.GitHubPath: ...
519513
@overload # noqa: E301
520514
def __new__(
521515
cls,
522516
*args: JoinablePathLike,
523517
protocol: Literal["hdfs"],
524-
chain_parser: FSSpecChainParser = ...,
525-
**storage_options: Any,
518+
**_: Any,
526519
) -> _uimpl.hdfs.HDFSPath: ...
527520
@overload # noqa: E301
528521
def __new__(
529522
cls,
530523
*args: JoinablePathLike,
531524
protocol: Literal["http", "https"],
532-
chain_parser: FSSpecChainParser = ...,
533-
**storage_options: Any,
525+
**_: Any,
534526
) -> _uimpl.http.HTTPPath: ...
535527
@overload # noqa: E301
536528
def __new__(
537529
cls,
538530
*args: JoinablePathLike,
539531
protocol: Literal["file", "local"],
540-
chain_parser: FSSpecChainParser = ...,
541-
**storage_options: Any,
532+
**_: Any,
542533
) -> _uimpl.local.FilePath: ...
543534
@overload # noqa: E301
544535
def __new__(
545536
cls,
546537
*args: JoinablePathLike,
547538
protocol: Literal["memory"],
548-
chain_parser: FSSpecChainParser = ...,
549-
**storage_options: Any,
539+
**_: Any,
550540
) -> _uimpl.memory.MemoryPath: ...
551541
@overload # noqa: E301
552542
def __new__(
553543
cls,
554544
*args: JoinablePathLike,
555545
protocol: Literal["sftp", "ssh"],
556-
chain_parser: FSSpecChainParser = ...,
557-
**storage_options: Any,
546+
**_: Any,
558547
) -> _uimpl.sftp.SFTPPath: ...
559548
@overload # noqa: E301
560549
def __new__(
561550
cls,
562551
*args: JoinablePathLike,
563552
protocol: Literal["smb"],
564-
chain_parser: FSSpecChainParser = ...,
565-
**storage_options: Any,
553+
**_: Any,
566554
) -> _uimpl.smb.SMBPath: ...
567555
@overload # noqa: E301
568556
def __new__(
569557
cls,
570558
*args: JoinablePathLike,
571559
protocol: Literal["tar"],
572-
chain_parser: FSSpecChainParser = ...,
573-
**storage_options: Any,
560+
**_: Any,
574561
) -> _uimpl.tar.TarPath: ...
575562
@overload # noqa: E301
576563
def __new__(
577564
cls,
578565
*args: JoinablePathLike,
579566
protocol: Literal["webdav"],
580-
chain_parser: FSSpecChainParser = ...,
581-
**storage_options: Any,
567+
**_: Any,
582568
) -> _uimpl.webdav.WebdavPath: ...
583569
@overload # noqa: E301
584570
def __new__(
585571
cls,
586572
*args: JoinablePathLike,
587573
protocol: Literal["zip"],
588-
chain_parser: FSSpecChainParser = ...,
589-
**storage_options: Any,
574+
**_: Any,
590575
) -> _uimpl.zip.ZipPath: ...
591576

592577
if sys.platform == "win32":
@@ -596,8 +581,7 @@ def __new__(
596581
cls,
597582
*args: JoinablePathLike,
598583
protocol: Literal[""],
599-
chain_parser: FSSpecChainParser = ...,
600-
**storage_options: Any,
584+
**_: Any,
601585
) -> _uimpl.local.WindowsUPath: ...
602586

603587
else:
@@ -607,17 +591,15 @@ def __new__(
607591
cls,
608592
*args: JoinablePathLike,
609593
protocol: Literal[""],
610-
chain_parser: FSSpecChainParser = ...,
611-
**storage_options: Any,
594+
**_: Any,
612595
) -> _uimpl.local.PosixUPath: ...
613596

614597
@overload # noqa: E301
615598
def __new__(
616599
cls,
617600
*args: JoinablePathLike,
618601
protocol: str | None = ...,
619-
chain_parser: FSSpecChainParser = ...,
620-
**storage_options: Any,
602+
**_: Any,
621603
) -> Self: ...
622604

623605
def __new__(

upath/extensions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ def _chain(self):
7878
protocol=self.__wrapped__.protocol,
7979
storage_options=dict(self.__wrapped__.storage_options),
8080
),
81-
[],
82-
[],
8381
)
8482

8583
# === wrapped interface ===========================================

upath/implementations/cloud.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from typing_extensions import Unpack
2222

2323
from upath._chain import FSSpecChainParser
24-
from upath.types.storage_options import AzureBlobStorageOptions
24+
from upath.types.storage_options import AzureStorageOptions
2525
from upath.types.storage_options import GCSStorageOptions
2626
from upath.types.storage_options import S3StorageOptions
2727

@@ -150,7 +150,7 @@ def __init__(
150150
*args: JoinablePathLike,
151151
protocol: Literal["abfs", "abfss", "adl", "az"] | None = None,
152152
chain_parser: FSSpecChainParser = DEFAULT_CHAIN_PARSER,
153-
**storage_options: Unpack[AzureBlobStorageOptions],
153+
**storage_options: Unpack[AzureStorageOptions],
154154
) -> None:
155155
super().__init__(
156156
*args, protocol=protocol, chain_parser=chain_parser, **storage_options

upath/implementations/github.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
from typing_extensions import Unpack
2424

2525
from upath._chain import FSSpecChainParser
26-
from upath.types.storage_options import GithubStorageOptions
26+
from upath.types.storage_options import GitHubStorageOptions
2727

2828
__all__ = ["GitHubPath"]
2929

@@ -42,7 +42,7 @@ def __init__(
4242
*args: JoinablePathLike,
4343
protocol: Literal["github"] | None = ...,
4444
chain_parser: FSSpecChainParser = ...,
45-
**storage_options: Unpack[GithubStorageOptions],
45+
**storage_options: Unpack[GitHubStorageOptions],
4646
) -> None: ...
4747

4848
@property

upath/types/storage_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@
1818
"SimpleCacheStorageOptions",
1919
"GCSStorageOptions",
2020
"S3StorageOptions",
21-
"AzureBlobStorageOptions",
21+
"AzureStorageOptions",
2222
"DataStorageOptions",
23-
"GithubStorageOptions",
23+
"GitHubStorageOptions",
2424
"HDFSStorageOptions",
2525
"HTTPStorageOptions",
2626
"FileStorageOptions",
@@ -142,7 +142,7 @@ class S3StorageOptions(_AbstractStorageOptions, total=False):
142142
cache_regions: bool
143143

144144

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

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

190190

191-
class GithubStorageOptions(_AbstractStorageOptions, total=False):
191+
class GitHubStorageOptions(_AbstractStorageOptions, total=False):
192192
"""Storage options for GitHub repository filesystem"""
193193

194194
# Repository identification

0 commit comments

Comments
 (0)