Skip to content

Commit

Permalink
Merge pull request #3086 from aatle/change-pathlike
Browse files Browse the repository at this point in the history
Make `pygame.typing.PathLike` internal/private
  • Loading branch information
damusss authored Aug 31, 2024
2 parents 06177e7 + e9aeb03 commit b0d45d1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions buildconfig/stubs/pygame/rwobject.pyi
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from typing import Any, Optional, overload, Type

from pygame.typing import PathLike
from pygame.typing import _PathLike

def encode_string(
obj: Optional[PathLike],
obj: Optional[_PathLike],
encoding: Optional[str] = "unicode_escape",
errors: Optional[str] = "backslashreplace",
etype: Optional[Type[Exception]] = UnicodeEncodeError,
) -> bytes: ...
@overload
def encode_file_path(
obj: Optional[PathLike], etype: Optional[Type[Exception]] = UnicodeEncodeError
obj: Optional[_PathLike], etype: Optional[Type[Exception]] = UnicodeEncodeError
) -> bytes: ...
@overload
def encode_file_path(
Expand Down
5 changes: 2 additions & 3 deletions buildconfig/stubs/pygame/typing.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ __all__ = [
"RectLike",
"SequenceLike",
"FileLike",
"PathLike",
"ColorLike",
"RGBATuple",
"Coordinate",
Expand All @@ -29,9 +28,9 @@ else:


# For functions that take a file name
PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
# Most pygame functions that take a file argument should be able to handle a FileLike type
FileLike = Union[PathLike, IO[bytes], IO[str]]
FileLike = Union[_PathLike, IO[bytes], IO[str]]

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

Expand Down
4 changes: 2 additions & 2 deletions buildconfig/stubs/typing_sample_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ def validator_SequenceLikeTypes(
)


# validate PathLike
# validate _PathLike
class MyPath:
def __fspath__(self) -> str:
return "file.py"

def validator_PathLike(path: typing.PathLike) -> int:
def validator_PathLike(path: typing._PathLike) -> int:
return 0

# must pass
Expand Down
15 changes: 6 additions & 9 deletions docs/reST/ref/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,17 @@ A lot of pygame functions and methods allow the user to provide different types
for the same value like colors or coordinates. This module exports the most common
type aliases for proper typehint annotations.

.. data:: PathLike
.. data:: FileLike

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

* ``"my/string/path.txt"``
* ``open("my/file/path.txt")``
* ``pathlib.Path("my/pathlib/path.txt")``
* ``io.BytesIO(b"my data: \x00\x01")``
* ``b"my/bytes/path.txt"``
* Any object implementing the path protocol (with a ``__fspath__`` magic method)

.. data:: FileLike

An object representing a file. Same as :mod:`pygame.typing.PathLike` with
the addition of file buffers (``IO`` of strings or bytes) such as the
return value of ``open()``.
* Any object implementing the path protocol or file protocol.

.. data:: SequenceLike

Expand Down
1 change: 0 additions & 1 deletion src_c/doc/typing_doc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* Auto generated file: with make_docs.py . Docs go in docs/reST/ref/ . */
#define DOC_TYPING "pygame module providing common typehints"
#define DOC_TYPING_PATHLIKE ""
#define DOC_TYPING_FILELIKE ""
#define DOC_TYPING_SEQUENCELIKE ""
#define DOC_TYPING_COORDINATE ""
Expand Down
5 changes: 2 additions & 3 deletions src_py/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"RectLike",
"SequenceLike",
"FileLike",
"PathLike",
"ColorLike",
"RGBATuple",
"Coordinate",
Expand All @@ -29,9 +28,9 @@ def __fspath__(self) -> _AnyStr_co: ...


# For functions that take a file name
PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
_PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
# Most pygame functions that take a file argument should be able to handle a FileLike type
FileLike = Union[PathLike, IO[bytes], IO[str]]
FileLike = Union[_PathLike, IO[bytes], IO[str]]

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

Expand Down

0 comments on commit b0d45d1

Please sign in to comment.