diff --git a/.flake8 b/.flake8 index b9b86734..ac4413f5 100644 --- a/.flake8 +++ b/.flake8 @@ -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 \ No newline at end of file diff --git a/cairo/__init__.pyi b/cairo/__init__.pyi index a2b969c6..cd2cae6c 100644 --- a/cairo/__init__.pyi +++ b/cairo/__init__.pyi @@ -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`) @@ -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`) diff --git a/pyproject.toml b/pyproject.toml index a5e5e71a..29604001 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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", diff --git a/tests/test_surface.py b/tests/test_surface.py index c0489e3e..ee51fe42 100644 --- a/tests/test_surface.py +++ b/tests/test_surface.py @@ -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)