Skip to content

Use FileDescriptorOrPath in stubs #9695

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 9, 2023
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
4 changes: 2 additions & 2 deletions stubs/Pillow/PIL/ImageFont.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import Incomplete, StrOrBytesPath, SupportsRead
from _typeshed import FileDescriptorOrPath, Incomplete, SupportsRead
from typing import Any, Protocol
from typing_extensions import Literal

Expand Down Expand Up @@ -109,7 +109,7 @@ class TransposedFont:
def getsize(self, text: str | bytes, *args, **kwargs) -> tuple[int, int]: ...
def getmask(self, text: str | bytes, mode: str = ..., *args, **kwargs): ...

def load(filename: StrOrBytesPath | int) -> ImageFont: ...
def load(filename: FileDescriptorOrPath) -> ImageFont: ...
def truetype(
font: str | bytes | SupportsRead[bytes] | None = ...,
size: int = ...,
Expand Down
7 changes: 2 additions & 5 deletions stubs/Pygments/pygments/lexers/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
from _typeshed import Incomplete, StrOrBytesPath, StrPath
from _typeshed import FileDescriptorOrPath, Incomplete, StrPath
from collections.abc import Iterator
from typing import Any
from typing_extensions import TypeAlias

from pygments.lexer import Lexer, LexerMeta

_OpenFile: TypeAlias = StrOrBytesPath | int # copy/pasted from builtins.pyi

def get_all_lexers(plugins: bool = ...) -> Iterator[tuple[str, tuple[str, ...], tuple[str, ...], tuple[str, ...]]]: ...
def find_lexer_class(name: str) -> LexerMeta | None: ...
def find_lexer_class_by_name(_alias: str) -> LexerMeta: ...
def get_lexer_by_name(_alias: str, **options: Any) -> Lexer: ...
def load_lexer_from_file(filename: _OpenFile, lexername: str = ..., **options: Any) -> Lexer: ...
def load_lexer_from_file(filename: FileDescriptorOrPath, lexername: str = ..., **options: Any) -> Lexer: ...
def find_lexer_class_for_filename(_fn: StrPath, code: str | bytes | None = ...) -> LexerMeta | None: ...
def get_lexer_for_filename(_fn: StrPath, code: str | bytes | None = ..., **options: Any) -> Lexer: ...
def get_lexer_for_mimetype(_mime: str, **options: Any) -> Lexer: ...
Expand Down
7 changes: 2 additions & 5 deletions stubs/aiofiles/aiofiles/os.pyi
Original file line number Diff line number Diff line change
@@ -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 = ...,
Expand Down
18 changes: 9 additions & 9 deletions stubs/aiofiles/aiofiles/ospath.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
13 changes: 6 additions & 7 deletions stubs/aiofiles/aiofiles/threadpool/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from _typeshed import (
FileDescriptorOrPath,
Incomplete,
OpenBinaryMode,
OpenBinaryModeReading,
OpenBinaryModeUpdating,
OpenBinaryModeWriting,
OpenTextMode,
StrOrBytesPath,
)
from asyncio import AbstractEventLoop
from collections.abc import Callable
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand All @@ -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 = ...,
Expand Down
4 changes: 2 additions & 2 deletions stubs/aiofiles/aiofiles/threadpool/binary.pyi
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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: ...
Expand Down
4 changes: 2 additions & 2 deletions stubs/aiofiles/aiofiles/threadpool/text.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from _typeshed import StrOrBytesPath
from _typeshed import FileDescriptorOrPath
from collections.abc import Iterable
from typing import BinaryIO

Expand Down Expand Up @@ -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: ...
7 changes: 2 additions & 5 deletions stubs/chevron/chevron/main.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
from _typeshed import StrOrBytesPath
from _typeshed import FileDescriptorOrPath
from typing import Any
from typing_extensions import TypeAlias

_OpenFile: TypeAlias = StrOrBytesPath | int

def main(template: _OpenFile, data: _OpenFile | None = ..., **kwargs: Any) -> str: ...
def main(template: FileDescriptorOrPath, data: FileDescriptorOrPath | None = ..., **kwargs: Any) -> str: ...
def cli_main() -> None: ...
10 changes: 5 additions & 5 deletions stubs/netaddr/netaddr/eui/ieee.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import _csv
from _typeshed import StrOrBytesPath
from _typeshed import FileDescriptorOrPath, StrOrBytesPath
from collections.abc import Iterable
from typing import Any, BinaryIO, TextIO
from typing_extensions import TypeAlias
Expand All @@ -12,21 +12,21 @@ IAB_INDEX: _INDEX

class FileIndexer(Subscriber):
writer: _csv._writer
def __init__(self, index_file: TextIO | StrOrBytesPath | int) -> None: ...
def __init__(self, index_file: TextIO | FileDescriptorOrPath) -> None: ...
def update(self, data: Iterable[Any]) -> None: ...

class OUIIndexParser(Publisher):
fh: BinaryIO
def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ...
def __init__(self, ieee_file: BinaryIO | FileDescriptorOrPath) -> None: ...
def parse(self) -> None: ...

class IABIndexParser(Publisher):
fh: BinaryIO
def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ...
def __init__(self, ieee_file: BinaryIO | FileDescriptorOrPath) -> None: ...
def parse(self) -> None: ...

def create_index_from_registry(
registry_fh: BinaryIO | StrOrBytesPath | int, index_path: StrOrBytesPath, parser: type[OUIIndexParser] | type[IABIndexParser]
registry_fh: BinaryIO | FileDescriptorOrPath, index_path: StrOrBytesPath, parser: type[OUIIndexParser] | type[IABIndexParser]
) -> None: ...
def create_indices() -> None: ...
def load_index(index: _INDEX, fp: Iterable[bytes]) -> None: ...
Expand Down
8 changes: 3 additions & 5 deletions stubs/pyinstaller/PyInstaller/compat.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
# https://pyinstaller.org/en/stable/hooks.html#module-PyInstaller.compat
from _typeshed import FileDescriptor, GenericPath, StrOrBytesPath
from _typeshed import FileDescriptorOrPath, GenericPath
from collections.abc import Iterable
from types import ModuleType
from typing import AnyStr, overload
from typing_extensions import Final, Literal, TypeAlias

_OpenFile: TypeAlias = StrOrBytesPath | FileDescriptor
from typing_extensions import Final, Literal

strict_collect_mode: bool
is_64bits: Final[bool]
Expand Down Expand Up @@ -48,7 +46,7 @@ architecture: Final[Literal["64bit", "n32bit", "32bit"]]
system: Final[Literal["Cygwin", "Linux", "Darwin", "Java", "Windows"]]
machine: Final[Literal["sw_64", "loongarch64", "arm", "intel", "ppc", "mips", "riscv", "s390x", "unknown", None]]

def is_wine_dll(filename: _OpenFile) -> bool: ...
def is_wine_dll(filename: FileDescriptorOrPath) -> bool: ...
@overload
def getenv(name: str, default: str) -> str: ...
@overload
Expand Down
2 changes: 0 additions & 2 deletions stubs/python-xlib/Xlib/_typing.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from _typeshed import FileDescriptor, StrOrBytesPath
from collections.abc import Callable
from typing import TypeVar
from typing_extensions import TypeAlias
Expand All @@ -9,4 +8,3 @@ from Xlib.protocol.rq import Request
_T = TypeVar("_T")
ErrorHandler: TypeAlias = Callable[[XError, Request | None], _T]
Unused: TypeAlias = object
OpenFile: TypeAlias = StrOrBytesPath | FileDescriptor
4 changes: 2 additions & 2 deletions stubs/python-xlib/Xlib/xauth.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from Xlib._typing import OpenFile
from _typeshed import FileDescriptorOrPath

FamilyInternet: int
FamilyDECnet: int
Expand All @@ -9,7 +9,7 @@ FamilyLocal: int

class Xauthority:
entries: list[tuple[bytes, bytes, bytes, bytes, bytes]]
def __init__(self, filename: OpenFile | None = ...) -> None: ...
def __init__(self, filename: FileDescriptorOrPath | None = ...) -> None: ...
def __len__(self) -> int: ...
def __getitem__(self, i: int) -> tuple[bytes, bytes, bytes, bytes, bytes]: ...
def get_best_auth(
Expand Down
4 changes: 2 additions & 2 deletions stubs/setuptools/setuptools/_distutils/dist.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from _typeshed import StrOrBytesPath, SupportsWrite
from _typeshed import FileDescriptorOrPath, SupportsWrite
from collections.abc import Iterable, Mapping
from distutils.cmd import Command
from typing import IO, Any

class DistributionMetadata:
def __init__(self, path: int | StrOrBytesPath | None = ...) -> None: ...
def __init__(self, path: FileDescriptorOrPath | None = ...) -> None: ...
name: str | None
version: str | None
author: str | None
Expand Down