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
How do I make PyGObject code PEP8 konform?
e.g.
#!/usr/bin/env python3
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
This code causes
E402 module level import not at top of file
E402 module level import not at top of file
__