Skip to content

Stub for ossaudiodev #4944

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

Merged
merged 4 commits into from
Jan 19, 2021
Merged

Stub for ossaudiodev #4944

merged 4 commits into from
Jan 19, 2021

Conversation

hauntsaninja
Copy link
Collaborator

One of the few remaining un-stubbed modules in the stdlib.

Note that this wasn't mentioned in #4545 since that list of
modules was determined on sys.platform == 'darwin'

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed two minor things below. Please merge after changing them.

Comment on lines 119 to 123
# TODO: oss_audio_device return type
@overload
def open(mode: str) -> Any: ...
@overload
def open(device: str, mode: str) -> Any: ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mode is Literal["r", "w", "rw"], according to the documentation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about this — wouldn't we need to have the broader str signature anyway, so that we fallback correctly? https://www.python.org/dev/peps/pep-0586/#interactions-with-overloads

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The situation described in the PEP is a bit different than here, I think. The PEP example has an overload, where other types depend on the literal value. Here, no other type depends on the literal. Also, the example in the PEP would be better written as mode: Literal["r", "rb"] = pick_file_mode(...), as this would be better than just returning str from pick_file_mode().

Off-topic aside: AnyOf could also help in the PEP example: Type checkers could treat a function foo with overloadsdef foo(x: Literal["b"]) -> bytes: ... and def foo(x: Literal["s"]) -> str: ... as also accepting def foo(x: Literal["s", "b"]) -> AnyOf[str, bytes]: ....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, made the change!

@srittau srittau merged commit 053e0df into python:master Jan 19, 2021
@hauntsaninja hauntsaninja deleted the ossaudio branch January 19, 2021 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants