From: James Addison <jay@jp-hosting.net>
Date: Tue, 01 Apr 2025 09:17:28 +0000
Subject: Raise import error if PyGObject module is empty
 .
 When GI overrides are installed, the dist-packages/gi directory is
 non-empty, and this allows Python3 to import the module.  This can
 happen when Debian packages other than python3-gi are installed.
 .
 Detect an empty __file__ attribute on the imported module to check
 whether it is genuinely the expected GObject Python module.
 .
 Credit to Francesco Ballarin for the test condition in #1101565.

Bug: http://bugs.debian.org/1101565
---
--- a/lib/matplotlib/backends/backend_gtk3.py
+++ b/lib/matplotlib/backends/backend_gtk3.py
@@ -11,6 +11,9 @@
 
 try:
     import gi
+
+    if gi.__file__ is None:
+        raise ImportError("Error: PyGObject module is empty")
 except ImportError as err:
     raise ImportError("The GTK3 backends require PyGObject") from err
 
--- a/lib/matplotlib/backends/backend_gtk4.py
+++ b/lib/matplotlib/backends/backend_gtk4.py
@@ -10,6 +10,9 @@
 
 try:
     import gi
+
+    if gi.__file__ is None:
+        raise ImportError("Error: PyGObject module is empty")
 except ImportError as err:
     raise ImportError("The GTK4 backends require PyGObject") from err
 
