Code that uses PyGObject can't be PEP8 conformant without generating
version warnings. My practice is to minimise E402 by moving imports,
then add .flake8 file with;
[flake8]
# E402 module level import not at top of file
# gi.require_version() is required before later imports
ignore = E402
--
My take would be to ignore this specific line with a magic comment. Or, if
you really donʼt want to d that, a
from importlib import import_module # isnʼt that line wonderful?
Gtk = import_module('gi.repository.Gtk')
might do the trick.
(Note that I wrote it without having Python at hand; maybe y