Skip to content
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

Make pygame.typing.PathLike internal/private #3086

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
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: 3 additions & 12 deletions docs/reST/ref/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ 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

An object representing a file path, i.e.:

* ``"my/string/path.txt"``
* ``pathlib.Path("my/pathlib/path.txt")``
* ``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()``.
An object representing a file. This includes any path-like objects such as
damusss marked this conversation as resolved.
Show resolved Hide resolved
``str`` or ``pathlib.Path()`` and file buffers (``IO`` of strings or bytes)
such as the return value of ``open()``.

.. 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
Loading