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

Proposal: Remove pygame.typing.PathLike type from the API #3085

Closed
aatle opened this issue Aug 28, 2024 · 1 comment · Fixed by #3086
Closed

Proposal: Remove pygame.typing.PathLike type from the API #3085

aatle opened this issue Aug 28, 2024 · 1 comment · Fixed by #3086
Labels
type hints Type hint checking related tasks

Comments

@aatle
Copy link
Contributor

aatle commented Aug 28, 2024

From the discussion in #3080, I think it may be a good idea to remove typing.PathLike union type alias.
Here are some arguments for removing it or making it internal:

  • The pygame typing API has not been released yet (2.5.2); it is easier to add PathLike back in if it is useful than it is to remove PathLike if it is unnecessary
  • Only used in one place in pygame other than in typing.FileLike: inside rwobject.pyi as the parameter type for encode_string() and encode_file_path(). Though there could be more undiscovered uses
  • This specific union is too general; not very specific to pygame (unlike FileLike)
    • Was considered for addition to standard typing module in PEP 519, but ultimately not added
    • Currently exists as one of the stable _typeshed types: StrOrBytesPath
  • Slight name conflict with os.PathLike, which is used in the definition of pygame.typing.PathLike (confusing?)

Also proposing a separate but related internal change: Still use os.PathLike for python <=3.8 (where it is not generic), by defining the other type in the version conditional, as so:

if sys.version_info >= (3, 9):
    PathLike = Union[str, bytes, _PathProtocol[str], _PathProtocol[bytes]]
else:
    PathLike = Union[str, bytes, _PathProtocol]

This is so we don't have to define a custom internal protocol class with the same behavior as os.PathLike.

@damusss damusss added the type hints Type hint checking related tasks label Aug 28, 2024
@ankith26
Copy link
Member

I think the easiest solution here is to undocument it and make it private for now, and keep using it in the implementation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type hints Type hint checking related tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants
@ankith26 @damusss @aatle and others