-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Stub for ossaudiodev #4944
Conversation
There was a problem hiding this 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.
stdlib/3/ossaudiodev.pyi
Outdated
# TODO: oss_audio_device return type | ||
@overload | ||
def open(mode: str) -> Any: ... | ||
@overload | ||
def open(device: str, mode: str) -> Any: ... |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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]: ...
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, made the change!
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'