5
5
import pathlib
6
6
import sys
7
7
import types
8
- from collections .abc import Awaitable , Callable , Iterable
8
+ from collections .abc import Awaitable , Callable , Iterable , Sequence
9
9
from functools import partial
10
10
from io import BufferedRandom , BufferedReader , BufferedWriter , FileIO , TextIOWrapper
11
11
from typing import (
@@ -245,7 +245,7 @@ def __fspath__(self) -> str:
245
245
return os .fspath (self ._wrapped )
246
246
247
247
@overload
248
- def open (
248
+ async def open (
249
249
self ,
250
250
mode : OpenTextMode = "r" ,
251
251
buffering : int = - 1 ,
@@ -256,7 +256,7 @@ def open(
256
256
...
257
257
258
258
@overload
259
- def open (
259
+ async def open (
260
260
self ,
261
261
mode : OpenBinaryMode ,
262
262
buffering : Literal [0 ],
@@ -267,7 +267,7 @@ def open(
267
267
...
268
268
269
269
@overload
270
- def open (
270
+ async def open (
271
271
self ,
272
272
mode : OpenBinaryModeUpdating ,
273
273
buffering : Literal [- 1 , 1 ] = - 1 ,
@@ -278,7 +278,7 @@ def open(
278
278
...
279
279
280
280
@overload
281
- def open (
281
+ async def open (
282
282
self ,
283
283
mode : OpenBinaryModeWriting ,
284
284
buffering : Literal [- 1 , 1 ] = - 1 ,
@@ -289,7 +289,7 @@ def open(
289
289
...
290
290
291
291
@overload
292
- def open (
292
+ async def open (
293
293
self ,
294
294
mode : OpenBinaryModeReading ,
295
295
buffering : Literal [- 1 , 1 ] = - 1 ,
@@ -300,7 +300,7 @@ def open(
300
300
...
301
301
302
302
@overload
303
- def open (
303
+ async def open (
304
304
self ,
305
305
mode : OpenBinaryMode ,
306
306
buffering : int = - 1 ,
@@ -311,7 +311,7 @@ def open(
311
311
...
312
312
313
313
@overload
314
- def open (
314
+ async def open (
315
315
self ,
316
316
mode : str ,
317
317
buffering : int = - 1 ,
@@ -338,11 +338,53 @@ async def open(self, *args: Any, **kwargs: Any) -> _AsyncIOWrapper[IO[Any]]:
338
338
def __bytes__ (self ) -> bytes : ...
339
339
def __truediv__ (self , other : StrPath ) -> Path : ...
340
340
def __rtruediv__ (self , other : StrPath ) -> Path : ...
341
+ def __lt__ (self , other : Path | pathlib .PurePath ) -> bool : ...
342
+ def __le__ (self , other : Path | pathlib .PurePath ) -> bool : ...
343
+ def __gt__ (self , other : Path | pathlib .PurePath ) -> bool : ...
344
+ def __ge__ (self , other : Path | pathlib .PurePath ) -> bool : ...
345
+
346
+ # The following are ordered the same as in typeshed.
347
+
348
+ # Properties produced by __getattr__() - all synchronous.
349
+ @property
350
+ def parts (self ) -> tuple [str , ...]: ...
351
+ @property
352
+ def drive (self ) -> str : ...
353
+ @property
354
+ def root (self ) -> str : ...
355
+ @property
356
+ def anchor (self ) -> str : ...
357
+ @property
358
+ def name (self ) -> str : ...
359
+ @property
360
+ def suffix (self ) -> str : ...
361
+ @property
362
+ def suffixes (self ) -> list [str ]: ...
363
+ @property
364
+ def stem (self ) -> str : ...
365
+ @property
366
+ def parents (self ) -> Sequence [pathlib .Path ]: ... # TODO: Convert these to trio Paths?
367
+ @property
368
+ def parent (self ) -> Path : ...
369
+
370
+ # PurePath methods - synchronous.
371
+ def as_posix (self ) -> str : ...
372
+ def as_uri (self ) -> str : ...
373
+ def is_absolute (self ) -> bool : ...
374
+ def is_reserved (self ) -> bool : ...
375
+ def match (self , path_pattern : str ) -> bool : ...
376
+ def relative_to (self , * other : StrPath ) -> Path : ...
377
+ def with_name (self , name : str ) -> Path : ...
378
+ def with_suffix (self , suffix : str ) -> Path : ...
379
+ def joinpath (self , * other : StrPath ) -> Path : ...
341
380
342
- # wrapped methods handled by __getattr__
343
- async def absolute (self ) -> Path : ...
344
- async def as_posix (self ) -> str : ...
345
- async def as_uri (self ) -> str : ...
381
+ if sys .version_info >= (3 , 9 ):
382
+ def is_relative_to (self , * other : StrPath ) -> bool : ...
383
+ def with_stem (self , stem : str ) -> Path : ...
384
+
385
+ # pathlib.Path methods and properties - async.
386
+ @classmethod
387
+ async def cwd (self ) -> Path : ...
346
388
347
389
if sys .version_info >= (3 , 10 ):
348
390
async def stat (self , * , follow_symlinks : bool = True ) -> os .stat_result : ...
@@ -351,51 +393,50 @@ async def chmod(self, mode: int, *, follow_symlinks: bool = True) -> None: ...
351
393
async def stat (self ) -> os .stat_result : ...
352
394
async def chmod (self , mode : int ) -> None : ...
353
395
354
- @classmethod
355
- async def cwd (self ) -> Path : ...
356
-
357
396
async def exists (self ) -> bool : ...
358
- async def expanduser (self ) -> Path : ...
359
397
async def glob (self , pattern : str ) -> Iterable [Path ]: ...
360
- async def home (self ) -> Path : ...
361
- async def is_absolute (self ) -> bool : ...
362
- async def is_block_device (self ) -> bool : ...
363
- async def is_char_device (self ) -> bool : ...
364
398
async def is_dir (self ) -> bool : ...
365
- async def is_fifo (self ) -> bool : ...
366
399
async def is_file (self ) -> bool : ...
367
- async def is_reserved (self ) -> bool : ...
368
- async def is_socket (self ) -> bool : ...
369
400
async def is_symlink (self ) -> bool : ...
401
+ async def is_socket (self ) -> bool : ...
402
+ async def is_fifo (self ) -> bool : ...
403
+ async def is_block_device (self ) -> bool : ...
404
+ async def is_char_device (self ) -> bool : ...
370
405
async def iterdir (self ) -> Iterable [Path ]: ...
371
- async def joinpath (self , * other : StrPath ) -> Path : ...
372
406
async def lchmod (self , mode : int ) -> None : ...
373
407
async def lstat (self ) -> os .stat_result : ...
374
- async def match (self , path_pattern : str ) -> bool : ...
375
408
async def mkdir (self , mode : int = 0o777 , parents : bool = False , exist_ok : bool = False ) -> None : ...
376
- async def read_bytes (self ) -> bytes : ...
377
- async def read_text (self , encoding : str | None = None , errors : str | None = None ) -> str : ...
378
- async def relative_to (self , * other : StrPath ) -> Path : ...
379
409
410
+ if sys .platform != "win32" :
411
+ async def owner (self ) -> str : ...
412
+ async def group (self ) -> str : ...
413
+ async def is_mount (self ) -> bool : ...
414
+ if sys .version_info >= (3 , 9 ):
415
+ async def readlink (self ) -> Path : ...
380
416
if sys .version_info >= (3 , 8 ):
381
- def rename (self , target : str | pathlib . PurePath ) -> Path : ...
382
- def replace (self , target : str | pathlib . PurePath ) -> Path : ...
417
+ async def rename (self , target : StrPath ) -> Path : ...
418
+ async def replace (self , target : StrPath ) -> Path : ...
383
419
else :
384
- def rename (self , target : str | pathlib .PurePath ) -> None : ...
385
- def replace (self , target : str | pathlib .PurePath ) -> None : ...
386
-
420
+ async def rename (self , target : StrPath ) -> None : ...
421
+ async def replace (self , target : StrPath ) -> None : ...
387
422
async def resolve (self , strict : bool = False ) -> Path : ...
388
423
async def rglob (self , pattern : str ) -> Iterable [Path ]: ...
389
424
async def rmdir (self ) -> None : ...
390
- async def samefile (self , other_path : str | bytes | int | Path ) -> bool : ...
391
- async def symlink_to (self , target : str | Path , target_is_directory : bool = False ) -> None : ...
425
+ async def symlink_to (self , target : StrPath , target_is_directory : bool = False ) -> None : ...
426
+ if sys .version_info >= (3 , 10 ):
427
+ async def hardlink_to (self , target : str | pathlib .Path ) -> None : ...
392
428
async def touch (self , mode : int = 0o666 , exist_ok : bool = True ) -> None : ...
393
429
if sys .version_info >= (3 , 8 ):
394
- def unlink (self , missing_ok : bool = False ) -> None : ...
430
+ async def unlink (self , missing_ok : bool = False ) -> None : ...
395
431
else :
396
- def unlink (self ) -> None : ...
397
- async def with_name (self , name : str ) -> Path : ...
398
- async def with_suffix (self , suffix : str ) -> Path : ...
432
+ async def unlink (self ) -> None : ...
433
+ @classmethod
434
+ async def home (self ) -> Path : ...
435
+ async def absolute (self ) -> Path : ...
436
+ async def expanduser (self ) -> Path : ...
437
+ async def read_bytes (self ) -> bytes : ...
438
+ async def read_text (self , encoding : str | None = None , errors : str | None = None ) -> str : ...
439
+ async def samefile (self , other_path : bytes | int | StrPath ) -> bool : ...
399
440
async def write_bytes (self , data : bytes ) -> int : ...
400
441
401
442
if sys .version_info >= (3 , 10 ):
@@ -412,17 +453,6 @@ async def write_text(
412
453
errors : str | None = None ,
413
454
) -> int : ...
414
455
415
- if sys .platform != "win32" :
416
- async def owner (self ) -> str : ...
417
- async def group (self ) -> str : ...
418
- async def is_mount (self ) -> bool : ...
419
-
420
- if sys .version_info >= (3 , 9 ):
421
- async def is_relative_to (self , * other : StrPath ) -> bool : ...
422
- async def with_stem (self , stem : str ) -> Path : ...
423
- async def readlink (self ) -> Path : ...
424
- if sys .version_info >= (3 , 10 ):
425
- async def hardlink_to (self , target : str | pathlib .Path ) -> None : ...
426
456
if sys .version_info < (3 , 12 ):
427
457
async def link_to (self , target : StrPath | bytes ) -> None : ...
428
458
if sys .version_info >= (3 , 12 ):
@@ -432,7 +462,7 @@ async def with_segments(self, *pathsegments: StrPath) -> Path: ...
432
462
433
463
434
464
Path .iterdir .__doc__ = """
435
- Like :meth:`pathlib.Path.iterdir`, but async.
465
+ Like :meth:`~ pathlib.Path.iterdir`, but async.
436
466
437
467
This is an async method that returns a synchronous iterator, so you
438
468
use it like::
@@ -446,6 +476,17 @@ async def with_segments(self, *pathsegments: StrPath) -> Path: ...
446
476
447
477
"""
448
478
479
+ if sys .version_info < (3 , 12 ):
480
+ # Since we synthesise methods from the stdlib, this automatically will
481
+ # have deprecation warnings, and disappear entirely in 3.12+.
482
+ Path .link_to .__doc__ = """
483
+ Like Python 3.8-3.11's :meth:`~pathlib.Path.link_to`, but async.
484
+
485
+ :deprecated: This method was deprecated in Python 3.10 and entirely \
486
+ removed in 3.12. Use :meth:`hardlink_to` instead which has \
487
+ a more meaningful parameter order.
488
+ """
489
+
449
490
# The value of Path.absolute.__doc__ makes a reference to
450
491
# :meth:~pathlib.Path.absolute, which does not exist. Removing this makes more
451
492
# sense than inventing our own special docstring for this.
0 commit comments