Skip to content

Commit b0d45d1

Browse files
authored
Merge pull request #3086 from aatle/change-pathlike
Make `pygame.typing.PathLike` internal/private
2 parents 06177e7 + e9aeb03 commit b0d45d1

File tree

6 files changed

+15
-21
lines changed

6 files changed

+15
-21
lines changed

buildconfig/stubs/pygame/rwobject.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
from typing import Any, Optional, overload, Type
22

3-
from pygame.typing import PathLike
3+
from pygame.typing import _PathLike
44

55
def encode_string(
6-
obj: Optional[PathLike],
6+
obj: Optional[_PathLike],
77
encoding: Optional[str] = "unicode_escape",
88
errors: Optional[str] = "backslashreplace",
99
etype: Optional[Type[Exception]] = UnicodeEncodeError,
1010
) -> bytes: ...
1111
@overload
1212
def encode_file_path(
13-
obj: Optional[PathLike], etype: Optional[Type[Exception]] = UnicodeEncodeError
13+
obj: Optional[_PathLike], etype: Optional[Type[Exception]] = UnicodeEncodeError
1414
) -> bytes: ...
1515
@overload
1616
def encode_file_path(

buildconfig/stubs/pygame/typing.pyi

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ __all__ = [
77
"RectLike",
88
"SequenceLike",
99
"FileLike",
10-
"PathLike",
1110
"ColorLike",
1211
"RGBATuple",
1312
"Coordinate",
@@ -29,9 +28,9 @@ else:
2928

3029

3130
# For functions that take a file name
32-
PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
31+
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
3332
# Most pygame functions that take a file argument should be able to handle a FileLike type
34-
FileLike = Union[PathLike, IO[bytes], IO[str]]
33+
FileLike = Union[_PathLike, IO[bytes], IO[str]]
3534

3635
_T_co = TypeVar("_T_co", covariant=True)
3736

buildconfig/stubs/typing_sample_app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ def validator_SequenceLikeTypes(
4444
)
4545

4646

47-
# validate PathLike
47+
# validate _PathLike
4848
class MyPath:
4949
def __fspath__(self) -> str:
5050
return "file.py"
5151

52-
def validator_PathLike(path: typing.PathLike) -> int:
52+
def validator_PathLike(path: typing._PathLike) -> int:
5353
return 0
5454

5555
# must pass

docs/reST/ref/typing.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,17 @@ A lot of pygame functions and methods allow the user to provide different types
1414
for the same value like colors or coordinates. This module exports the most common
1515
type aliases for proper typehint annotations.
1616

17-
.. data:: PathLike
17+
.. data:: FileLike
1818

19-
An object representing a file path, i.e.:
19+
An object representing a file. This includes both path-like
20+
objects and file-like objects, i.e.:
2021

2122
* ``"my/string/path.txt"``
23+
* ``open("my/file/path.txt")``
2224
* ``pathlib.Path("my/pathlib/path.txt")``
25+
* ``io.BytesIO(b"my data: \x00\x01")``
2326
* ``b"my/bytes/path.txt"``
24-
* Any object implementing the path protocol (with a ``__fspath__`` magic method)
25-
26-
.. data:: FileLike
27-
28-
An object representing a file. Same as :mod:`pygame.typing.PathLike` with
29-
the addition of file buffers (``IO`` of strings or bytes) such as the
30-
return value of ``open()``.
27+
* Any object implementing the path protocol or file protocol.
3128

3229
.. data:: SequenceLike
3330

src_c/doc/typing_doc.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* Auto generated file: with make_docs.py . Docs go in docs/reST/ref/ . */
22
#define DOC_TYPING "pygame module providing common typehints"
3-
#define DOC_TYPING_PATHLIKE ""
43
#define DOC_TYPING_FILELIKE ""
54
#define DOC_TYPING_SEQUENCELIKE ""
65
#define DOC_TYPING_COORDINATE ""

src_py/typing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
"RectLike",
88
"SequenceLike",
99
"FileLike",
10-
"PathLike",
1110
"ColorLike",
1211
"RGBATuple",
1312
"Coordinate",
@@ -29,9 +28,9 @@ def __fspath__(self) -> _AnyStr_co: ...
2928

3029

3130
# For functions that take a file name
32-
PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
31+
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
3332
# Most pygame functions that take a file argument should be able to handle a FileLike type
34-
FileLike = Union[PathLike, IO[bytes], IO[str]]
33+
FileLike = Union[_PathLike, IO[bytes], IO[str]]
3534

3635
_T_co = TypeVar("_T_co", covariant=True)
3736

0 commit comments

Comments
 (0)