Skip to content

brain_gi uses wrong Gtk version for analysis #2190

Open
@kulikjak

Description

@kulikjak

Steps to reproduce

This only happens on systems where both Gtk 3 and Gtk 4 are available.

import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

cell = Gtk.CellRendererText()
#cell.props.xalign = 1.0

Gtk.Builder().connect_signals({})

When you run pylint on this code, it works as expected; however, when you uncomment the cell.props.xalign line, it breaks with
test.py:8:0: E1101: Instance of 'Builder' has no 'connect_signals' member (no-member)
(connect_signals is only available in Gtk3, not in Gtk4)

Current behavior

test.py:8:0: E1101: Instance of 'Builder' has no 'connect_signals' member (no-member)

Expected behavior

E1101 is not there (as Builder does have connect_signals member in Gtk 3.0).

More info

I did a little bit more digging and found out that in the second (failing) case, following exception is raised in _register_require_version:
Namespace Gtk is already loaded with version 4.0

Debug prints in each function in brain_gi.py further showed that in the first case, require_version is handled first as expected. In the second case, _register_require_version is called after everything else has been processed, which is wrong (newer Gtk was already loaded at this point).

I found this in astroid 2.12.5 and pylint 2.15.2 with Python 3.7 and 3.11, but I also tried the latest and greatest (astroid 2.15.5 & pylint 2.17.4), and the same issue is still reproducible.

This issue was initially reported here:
pylint-dev/pylint#6352

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions