Use _typeshed.FileDescriptorOrPath in stubs (#9695)

This commit is contained in:
Avasam
2023-02-09 02:30:19 -05:00
committed by GitHub
parent 6d535bf0a3
commit 372073d35b
13 changed files with 39 additions and 53 deletions

View File

@@ -1,19 +1,16 @@
import sys
from _typeshed import GenericPath, StrOrBytesPath
from _typeshed import FileDescriptorOrPath, GenericPath, StrOrBytesPath
from asyncio.events import AbstractEventLoop
from collections.abc import Sequence
from os import _ScandirIterator, stat_result
from typing import Any, AnyStr, overload
from typing_extensions import TypeAlias
from aiofiles import ospath
path = ospath
_FdOrAnyPath: TypeAlias = int | StrOrBytesPath
async def stat(
path: _FdOrAnyPath,
path: FileDescriptorOrPath,
*,
dir_fd: int | None = ...,
follow_symlinks: bool = ...,

View File

@@ -1,15 +1,15 @@
from _typeshed import StrOrBytesPath
from _typeshed import FileDescriptorOrPath
from asyncio.events import AbstractEventLoop
from typing import Any
async def exists(path: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def isfile(path: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def isdir(s: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def getsize(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> int: ...
async def getmtime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def getatime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def getctime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def exists(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def isfile(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def isdir(s: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
async def getsize(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> int: ...
async def getmtime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def getatime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def getctime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
async def samefile(
f1: StrOrBytesPath | int, f2: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...
f1: FileDescriptorOrPath, f2: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...
) -> bool: ...
async def sameopenfile(fp1: int, fp2: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...

View File

@@ -1,11 +1,11 @@
from _typeshed import (
FileDescriptorOrPath,
Incomplete,
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
StrOrBytesPath,
)
from asyncio import AbstractEventLoop
from collections.abc import Callable
@@ -16,13 +16,12 @@ from ..base import AiofilesContextManager
from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO, _UnknownAsyncBinaryIO
from .text import AsyncTextIOWrapper
_OpenFile: TypeAlias = StrOrBytesPath | int
_Opener: TypeAlias = Callable[[str, int], int]
# Text mode: always returns AsyncTextIOWrapper
@overload
def open(
file: _OpenFile,
file: FileDescriptorOrPath,
mode: OpenTextMode = ...,
buffering: int = ...,
encoding: str | None = ...,
@@ -38,7 +37,7 @@ def open(
# Unbuffered binary: returns a FileIO
@overload
def open(
file: _OpenFile,
file: FileDescriptorOrPath,
mode: OpenBinaryMode,
buffering: Literal[0],
encoding: None = ...,
@@ -54,7 +53,7 @@ def open(
# Buffered binary reading/updating: AsyncBufferedReader
@overload
def open(
file: _OpenFile,
file: FileDescriptorOrPath,
mode: OpenBinaryModeReading | OpenBinaryModeUpdating,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
@@ -70,7 +69,7 @@ def open(
# Buffered binary writing: AsyncBufferedIOBase
@overload
def open(
file: _OpenFile,
file: FileDescriptorOrPath,
mode: OpenBinaryModeWriting,
buffering: Literal[-1, 1] = ...,
encoding: None = ...,
@@ -86,7 +85,7 @@ def open(
# Buffering cannot be determined: fall back to _UnknownAsyncBinaryIO
@overload
def open(
file: _OpenFile,
file: FileDescriptorOrPath,
mode: OpenBinaryMode,
buffering: int = ...,
encoding: None = ...,

View File

@@ -1,4 +1,4 @@
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer
from collections.abc import Iterable
from io import FileIO
@@ -26,7 +26,7 @@ class _UnknownAsyncBinaryIO(AsyncBase[bytes]):
@property
def mode(self) -> str: ...
@property
def name(self) -> StrOrBytesPath | int: ...
def name(self) -> FileDescriptorOrPath: ...
class AsyncBufferedIOBase(_UnknownAsyncBinaryIO):
async def read1(self, __size: int = ...) -> bytes: ...

View File

@@ -1,4 +1,4 @@
from _typeshed import StrOrBytesPath
from _typeshed import FileDescriptorOrPath
from collections.abc import Iterable
from typing import BinaryIO
@@ -34,6 +34,6 @@ class AsyncTextIOWrapper(AsyncBase[str]):
@property
def newlines(self) -> str | tuple[str, ...] | None: ...
@property
def name(self) -> StrOrBytesPath | int: ...
def name(self) -> FileDescriptorOrPath: ...
@property
def mode(self) -> str: ...