Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
ignore=E402,E741
builtins=buffer,unichr
max-line-length = 100
max-line-length = 110
exclude = build,.git,.venv
filename = *.py,*.pyi
4 changes: 2 additions & 2 deletions cairo/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2307,7 +2307,7 @@ class Surface:
forth. The result can then be used with :class:`ScaledFont`.
"""

def get_mime_data(self, mime_type: str) -> Optional[bytes]:
def get_mime_data(self, mime_type: str) -> Union[bytes, bytearray, memoryview, None]:
"""
:param mime_type: the MIME type of the image data
(:ref:`constants_MIME_TYPE`)
Expand Down Expand Up @@ -2453,7 +2453,7 @@ class Surface:
.. versionadded:: 1.2
"""

def set_mime_data(self, mime_type: str, data: Optional[bytes]) -> None:
def set_mime_data(self, mime_type: str, data: Union[bytes, bytearray, memoryview, None]) -> None:
"""
:param mime_type: the MIME type of the image data
(:ref:`constants_MIME_TYPE`)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ optional = true
[dependency-groups]
dev = [
"pytest>=8.3.0,<10",
"mypy==1.18.2 ; platform_python_implementation != 'PyPy'",
"mypy==2.3.0 ; platform_python_implementation != 'PyPy'",
"flake8>=7.0.0,<8",
"coverage[toml]>=7.2.3,<8",
"meson-python>= 0.16.0",
Expand Down
12 changes: 12 additions & 0 deletions tests/test_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,18 @@ def test_surface_get_set_mime_data() -> None:
with pytest.raises(TypeError):
surface.get_mime_data(object()) # type: ignore

v = memoryview(b"bla")
surface.set_mime_data("foo", v)
assert surface.get_mime_data("foo") is v
surface.set_mime_data("foo", None)
assert surface.get_mime_data("foo") is None

vb = bytearray(b"bla")
surface.set_mime_data("foo", vb)
assert surface.get_mime_data("foo") is vb
surface.set_mime_data("foo", None)
assert surface.get_mime_data("foo") is None


def test_supports_mime_type() -> None:
surface = cairo.PDFSurface(None, 3, 3)
Expand Down
Loading