Skip to content

Commit 372073d

Browse files
authored
Use _typeshed.FileDescriptorOrPath in stubs (#9695)
1 parent 6d535bf commit 372073d

File tree

13 files changed

+39
-53
lines changed

13 files changed

+39
-53
lines changed

stubs/Pillow/PIL/ImageFont.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, StrOrBytesPath, SupportsRead
1+
from _typeshed import FileDescriptorOrPath, Incomplete, SupportsRead
22
from typing import Any, Protocol
33
from typing_extensions import Literal
44

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

112-
def load(filename: StrOrBytesPath | int) -> ImageFont: ...
112+
def load(filename: FileDescriptorOrPath) -> ImageFont: ...
113113
def truetype(
114114
font: str | bytes | SupportsRead[bytes] | None = ...,
115115
size: int = ...,

stubs/Pygments/pygments/lexers/__init__.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
from _typeshed import Incomplete, StrOrBytesPath, StrPath
1+
from _typeshed import FileDescriptorOrPath, Incomplete, StrPath
22
from collections.abc import Iterator
33
from typing import Any
4-
from typing_extensions import TypeAlias
54

65
from pygments.lexer import Lexer, LexerMeta
76

8-
_OpenFile: TypeAlias = StrOrBytesPath | int # copy/pasted from builtins.pyi
9-
107
def get_all_lexers(plugins: bool = ...) -> Iterator[tuple[str, tuple[str, ...], tuple[str, ...], tuple[str, ...]]]: ...
118
def find_lexer_class(name: str) -> LexerMeta | None: ...
129
def find_lexer_class_by_name(_alias: str) -> LexerMeta: ...
1310
def get_lexer_by_name(_alias: str, **options: Any) -> Lexer: ...
14-
def load_lexer_from_file(filename: _OpenFile, lexername: str = ..., **options: Any) -> Lexer: ...
11+
def load_lexer_from_file(filename: FileDescriptorOrPath, lexername: str = ..., **options: Any) -> Lexer: ...
1512
def find_lexer_class_for_filename(_fn: StrPath, code: str | bytes | None = ...) -> LexerMeta | None: ...
1613
def get_lexer_for_filename(_fn: StrPath, code: str | bytes | None = ..., **options: Any) -> Lexer: ...
1714
def get_lexer_for_mimetype(_mime: str, **options: Any) -> Lexer: ...

stubs/aiofiles/aiofiles/os.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import sys
2-
from _typeshed import GenericPath, StrOrBytesPath
2+
from _typeshed import FileDescriptorOrPath, GenericPath, StrOrBytesPath
33
from asyncio.events import AbstractEventLoop
44
from collections.abc import Sequence
55
from os import _ScandirIterator, stat_result
66
from typing import Any, AnyStr, overload
7-
from typing_extensions import TypeAlias
87

98
from aiofiles import ospath
109

1110
path = ospath
1211

13-
_FdOrAnyPath: TypeAlias = int | StrOrBytesPath
14-
1512
async def stat(
16-
path: _FdOrAnyPath,
13+
path: FileDescriptorOrPath,
1714
*,
1815
dir_fd: int | None = ...,
1916
follow_symlinks: bool = ...,

stubs/aiofiles/aiofiles/ospath.pyi

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
from _typeshed import StrOrBytesPath
1+
from _typeshed import FileDescriptorOrPath
22
from asyncio.events import AbstractEventLoop
33
from typing import Any
44

5-
async def exists(path: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
6-
async def isfile(path: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
7-
async def isdir(s: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
8-
async def getsize(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> int: ...
9-
async def getmtime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
10-
async def getatime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
11-
async def getctime(filename: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
5+
async def exists(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
6+
async def isfile(path: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
7+
async def isdir(s: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...
8+
async def getsize(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> int: ...
9+
async def getmtime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
10+
async def getatime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
11+
async def getctime(filename: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> float: ...
1212
async def samefile(
13-
f1: StrOrBytesPath | int, f2: StrOrBytesPath | int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...
13+
f1: FileDescriptorOrPath, f2: FileDescriptorOrPath, *, loop: AbstractEventLoop | None = ..., executor: Any = ...
1414
) -> bool: ...
1515
async def sameopenfile(fp1: int, fp2: int, *, loop: AbstractEventLoop | None = ..., executor: Any = ...) -> bool: ...

stubs/aiofiles/aiofiles/threadpool/__init__.pyi

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from _typeshed import (
2+
FileDescriptorOrPath,
23
Incomplete,
34
OpenBinaryMode,
45
OpenBinaryModeReading,
56
OpenBinaryModeUpdating,
67
OpenBinaryModeWriting,
78
OpenTextMode,
8-
StrOrBytesPath,
99
)
1010
from asyncio import AbstractEventLoop
1111
from collections.abc import Callable
@@ -16,13 +16,12 @@ from ..base import AiofilesContextManager
1616
from .binary import AsyncBufferedIOBase, AsyncBufferedReader, AsyncFileIO, _UnknownAsyncBinaryIO
1717
from .text import AsyncTextIOWrapper
1818

19-
_OpenFile: TypeAlias = StrOrBytesPath | int
2019
_Opener: TypeAlias = Callable[[str, int], int]
2120

2221
# Text mode: always returns AsyncTextIOWrapper
2322
@overload
2423
def open(
25-
file: _OpenFile,
24+
file: FileDescriptorOrPath,
2625
mode: OpenTextMode = ...,
2726
buffering: int = ...,
2827
encoding: str | None = ...,
@@ -38,7 +37,7 @@ def open(
3837
# Unbuffered binary: returns a FileIO
3938
@overload
4039
def open(
41-
file: _OpenFile,
40+
file: FileDescriptorOrPath,
4241
mode: OpenBinaryMode,
4342
buffering: Literal[0],
4443
encoding: None = ...,
@@ -54,7 +53,7 @@ def open(
5453
# Buffered binary reading/updating: AsyncBufferedReader
5554
@overload
5655
def open(
57-
file: _OpenFile,
56+
file: FileDescriptorOrPath,
5857
mode: OpenBinaryModeReading | OpenBinaryModeUpdating,
5958
buffering: Literal[-1, 1] = ...,
6059
encoding: None = ...,
@@ -70,7 +69,7 @@ def open(
7069
# Buffered binary writing: AsyncBufferedIOBase
7170
@overload
7271
def open(
73-
file: _OpenFile,
72+
file: FileDescriptorOrPath,
7473
mode: OpenBinaryModeWriting,
7574
buffering: Literal[-1, 1] = ...,
7675
encoding: None = ...,
@@ -86,7 +85,7 @@ def open(
8685
# Buffering cannot be determined: fall back to _UnknownAsyncBinaryIO
8786
@overload
8887
def open(
89-
file: _OpenFile,
88+
file: FileDescriptorOrPath,
9089
mode: OpenBinaryMode,
9190
buffering: int = ...,
9291
encoding: None = ...,

stubs/aiofiles/aiofiles/threadpool/binary.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import ReadableBuffer, StrOrBytesPath, WriteableBuffer
1+
from _typeshed import FileDescriptorOrPath, ReadableBuffer, WriteableBuffer
22
from collections.abc import Iterable
33
from io import FileIO
44

@@ -26,7 +26,7 @@ class _UnknownAsyncBinaryIO(AsyncBase[bytes]):
2626
@property
2727
def mode(self) -> str: ...
2828
@property
29-
def name(self) -> StrOrBytesPath | int: ...
29+
def name(self) -> FileDescriptorOrPath: ...
3030

3131
class AsyncBufferedIOBase(_UnknownAsyncBinaryIO):
3232
async def read1(self, __size: int = ...) -> bytes: ...

stubs/aiofiles/aiofiles/threadpool/text.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import StrOrBytesPath
1+
from _typeshed import FileDescriptorOrPath
22
from collections.abc import Iterable
33
from typing import BinaryIO
44

@@ -34,6 +34,6 @@ class AsyncTextIOWrapper(AsyncBase[str]):
3434
@property
3535
def newlines(self) -> str | tuple[str, ...] | None: ...
3636
@property
37-
def name(self) -> StrOrBytesPath | int: ...
37+
def name(self) -> FileDescriptorOrPath: ...
3838
@property
3939
def mode(self) -> str: ...

stubs/chevron/chevron/main.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
from _typeshed import StrOrBytesPath
1+
from _typeshed import FileDescriptorOrPath
22
from typing import Any
3-
from typing_extensions import TypeAlias
43

5-
_OpenFile: TypeAlias = StrOrBytesPath | int
6-
7-
def main(template: _OpenFile, data: _OpenFile | None = ..., **kwargs: Any) -> str: ...
4+
def main(template: FileDescriptorOrPath, data: FileDescriptorOrPath | None = ..., **kwargs: Any) -> str: ...
85
def cli_main() -> None: ...

stubs/netaddr/netaddr/eui/ieee.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import _csv
2-
from _typeshed import StrOrBytesPath
2+
from _typeshed import FileDescriptorOrPath, StrOrBytesPath
33
from collections.abc import Iterable
44
from typing import Any, BinaryIO, TextIO
55
from typing_extensions import TypeAlias
@@ -12,21 +12,21 @@ IAB_INDEX: _INDEX
1212

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

1818
class OUIIndexParser(Publisher):
1919
fh: BinaryIO
20-
def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ...
20+
def __init__(self, ieee_file: BinaryIO | FileDescriptorOrPath) -> None: ...
2121
def parse(self) -> None: ...
2222

2323
class IABIndexParser(Publisher):
2424
fh: BinaryIO
25-
def __init__(self, ieee_file: BinaryIO | StrOrBytesPath | int) -> None: ...
25+
def __init__(self, ieee_file: BinaryIO | FileDescriptorOrPath) -> None: ...
2626
def parse(self) -> None: ...
2727

2828
def create_index_from_registry(
29-
registry_fh: BinaryIO | StrOrBytesPath | int, index_path: StrOrBytesPath, parser: type[OUIIndexParser] | type[IABIndexParser]
29+
registry_fh: BinaryIO | FileDescriptorOrPath, index_path: StrOrBytesPath, parser: type[OUIIndexParser] | type[IABIndexParser]
3030
) -> None: ...
3131
def create_indices() -> None: ...
3232
def load_index(index: _INDEX, fp: Iterable[bytes]) -> None: ...

stubs/pyinstaller/PyInstaller/compat.pyi

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# https://pyinstaller.org/en/stable/hooks.html#module-PyInstaller.compat
2-
from _typeshed import FileDescriptor, GenericPath, StrOrBytesPath
2+
from _typeshed import FileDescriptorOrPath, GenericPath
33
from collections.abc import Iterable
44
from types import ModuleType
55
from typing import AnyStr, overload
6-
from typing_extensions import Final, Literal, TypeAlias
7-
8-
_OpenFile: TypeAlias = StrOrBytesPath | FileDescriptor
6+
from typing_extensions import Final, Literal
97

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

51-
def is_wine_dll(filename: _OpenFile) -> bool: ...
49+
def is_wine_dll(filename: FileDescriptorOrPath) -> bool: ...
5250
@overload
5351
def getenv(name: str, default: str) -> str: ...
5452
@overload

stubs/python-xlib/Xlib/_typing.pyi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from _typeshed import FileDescriptor, StrOrBytesPath
21
from collections.abc import Callable
32
from typing import TypeVar
43
from typing_extensions import TypeAlias
@@ -9,4 +8,3 @@ from Xlib.protocol.rq import Request
98
_T = TypeVar("_T")
109
ErrorHandler: TypeAlias = Callable[[XError, Request | None], _T]
1110
Unused: TypeAlias = object
12-
OpenFile: TypeAlias = StrOrBytesPath | FileDescriptor

stubs/python-xlib/Xlib/xauth.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from Xlib._typing import OpenFile
1+
from _typeshed import FileDescriptorOrPath
22

33
FamilyInternet: int
44
FamilyDECnet: int
@@ -9,7 +9,7 @@ FamilyLocal: int
99

1010
class Xauthority:
1111
entries: list[tuple[bytes, bytes, bytes, bytes, bytes]]
12-
def __init__(self, filename: OpenFile | None = ...) -> None: ...
12+
def __init__(self, filename: FileDescriptorOrPath | None = ...) -> None: ...
1313
def __len__(self) -> int: ...
1414
def __getitem__(self, i: int) -> tuple[bytes, bytes, bytes, bytes, bytes]: ...
1515
def get_best_auth(

stubs/setuptools/setuptools/_distutils/dist.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from _typeshed import StrOrBytesPath, SupportsWrite
1+
from _typeshed import FileDescriptorOrPath, SupportsWrite
22
from collections.abc import Iterable, Mapping
33
from distutils.cmd import Command
44
from typing import IO, Any
55

66
class DistributionMetadata:
7-
def __init__(self, path: int | StrOrBytesPath | None = ...) -> None: ...
7+
def __init__(self, path: FileDescriptorOrPath | None = ...) -> None: ...
88
name: str | None
99
version: str | None
1010
author: str | None

0 commit comments

Comments
 (0)