From eec6b60116e12e015387fe1fa3a729553d3848bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Sat, 22 May 2021 01:11:48 +0200
Subject: [PATCH] Force using GTK+3 in twisted.internet.gireactor

Modify twisted.internet.gireactor to explicitly request GTK+ version 3.
Otherwise it uses the newest version installed which could be GTK+4
that gireactor is currently incompatible with.
---
 src/twisted/internet/gireactor.py           | 3 +++
 src/twisted/internet/test/test_gireactor.py | 3 +++
 src/twisted/newsfragments/10200.bugfix      | 1 +
 3 files changed, 7 insertions(+)
 create mode 100644 src/twisted/newsfragments/10200.bugfix

diff --git a/src/twisted/internet/gireactor.py b/src/twisted/internet/gireactor.py
index 92596db1d..a577825a8 100644
--- a/src/twisted/internet/gireactor.py
+++ b/src/twisted/internet/gireactor.py
@@ -24,6 +24,7 @@ On Python 3, pygobject v3.4 or later is required.
 from twisted.internet.error import ReactorAlreadyRunning
 from twisted.internet import _glibbase
 from twisted.python import runtime
+import gi  # type: ignore[import]
 import gi.pygtkcompat  # type: ignore[import]
 from gi.repository import GLib  # type: ignore[import]
 
@@ -68,6 +69,7 @@ class GIReactor(_glibbase.GlibReactorBase):
     def __init__(self, useGtk=False):
         _gtk = None
         if useGtk is True:
+            gi.require_version("Gtk", "3.0")
             from gi.repository import Gtk as _gtk
 
         _glibbase.GlibReactorBase.__init__(self, GLib, _gtk, useGtk=useGtk)
@@ -112,6 +114,7 @@ class PortableGIReactor(_glibbase.PortableGlibReactorBase):
     def __init__(self, useGtk=False):
         _gtk = None
         if useGtk is True:
+            gi.require_version("Gtk", "3.0")
             from gi.repository import Gtk as _gtk
 
         _glibbase.PortableGlibReactorBase.__init__(self, GLib, _gtk, useGtk=useGtk)
diff --git a/src/twisted/internet/test/test_gireactor.py b/src/twisted/internet/test/test_gireactor.py
index d15a92622..af5092a36 100644
--- a/src/twisted/internet/test/test_gireactor.py
+++ b/src/twisted/internet/test/test_gireactor.py
@@ -25,6 +25,9 @@ else:
         gtk3reactor = None
     else:
         gtk3reactor = _gtk3reactor
+        import gi  # type: ignore[import]
+
+        gi.require_version("Gtk", "3.0")
         from gi.repository import Gtk
 
 from twisted.internet.error import ReactorAlreadyRunning
diff --git a/src/twisted/newsfragments/10200.bugfix b/src/twisted/newsfragments/10200.bugfix
new file mode 100644
index 000000000..7afb343be
--- /dev/null
+++ b/src/twisted/newsfragments/10200.bugfix
@@ -0,0 +1 @@
+twisted.internet.gireactor was fixed to force GTK+3 in order to fix use of incompatible GTK+4 API when installed
-- 
2.32.0

