PyGObject: pep8 konform

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

PyGObject: pep8 konform

c.buhtz
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
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: PyGObject: pep8 konform

Gergely Polonkai
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 you have to
import gi.repository, and do getattr(repository, Gtk) instead.)

Best,
Gergely

On Fri, Jun 1, 2018, 14:47 <[hidden email]> wrote:

> 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
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: PyGObject: pep8 konform

James Cameron-2
In reply to this post by c.buhtz
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

--
James Cameron
http://quozl.netrek.org/
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list