-
Notifications
You must be signed in to change notification settings - Fork 41
Open
Description
The type annotation for GLib.Bytes.new() input argument data is confusingly narrow: Sequence[int].
pygobject-stubs/src/gi-stubs/repository/GLib.pyi
Line 1425 in a576d99
| def new(cls, data: typing.Optional[typing.Sequence[int]] = None) -> Bytes: ... |
Yet the following code works without a problem:
import io
import gi
from gi.repository import GLib
data = b"hi mom."
array = GLib.Bytes.new(data)
array = GLib.Bytes.new(bytearray(data))
array = GLib.Bytes.new(memoryview(data))
array = GLib.Bytes.new(io.BytesIO(data).getvalue())I think the type annotation should reflect this.
I made a PR that changes the type to typing.Union[typing.Sequence[int], bytes] but I'm neither sure that this will not have unwanted consequences for other classes nor that this is exhaustive for all the possible values shown above or what else might be legal to pass. I hope someone more knowledgeable can figure out what the maximal type annotation would be.
Metadata
Metadata
Assignees
Labels
No labels