Skip to content

Use exact signatures for GObject introspection bindings#3046

Open
oreiche wants to merge 2 commits into
pylint-dev:mainfrom
oreiche:oreiche/gi-exact-signatures
Open

Use exact signatures for GObject introspection bindings#3046
oreiche wants to merge 2 commits into
pylint-dev:mainfrom
oreiche:oreiche/gi-exact-signatures

Conversation

@oreiche

@oreiche oreiche commented May 7, 2026

Copy link
Copy Markdown
Contributor

Type of Changes

Type
✨ New feature

Description

With the recent change to use inspect.signature() (#2930), instead of generating signatures for all functions and methods with "wildcards" (*args, **kwargs), the exact signature could be provided for better linting.

Given the following example.py

"""Simple Example from https://python-gtk-3-tutorial.readthedocs.io/en/latest/introduction.html"""

import gi

gi.require_version("Gtk", "3.0")
from gi.repository import Gtk  # pylint: disable=wrong-import-position

win = Gtk.Window()
win.connect("destroy", Gtk.main_quit)
win.set_default_size(200)  # BUG: deliberately missing second argument
win.show_all()
Gtk.main()

... the missing second argument to set_default_size could be reported with a meaningful error message when using exact signatures:

$ pylint example.py 
************* Module example
example.py:10:0: E1120: No value for argument 'height' in method call (no-value-for-parameter)

------------------------------------------------------------------
Your code has been rated at 3.75/10 (previous run: 3.75/10, +0.00)

Risks

While this feature would substantially improve linting analysis, it would come at a noticeably higher computational cost during module loading time to generate the signatures.

Linting time for the example.py above

  • 5.63 sec
  • 8.87 sec (+58%)

Linting time for Apport's tests/system/test_ui_gtk.py

  • 8.71 sec
  • 11.45 sec (+31%)

Refs #2930

@codecov

codecov Bot commented May 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 3.84615% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.37%. Comparing base (3258d5f) to head (b3773cb).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
astroid/brain/brain_gi.py 3.84% 25 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3046      +/-   ##
==========================================
- Coverage   93.56%   93.37%   -0.19%     
==========================================
  Files          92       92              
  Lines       11340    11364      +24     
==========================================
+ Hits        10610    10611       +1     
- Misses        730      753      +23     
Flag Coverage Δ
linux 93.24% <3.84%> (-0.19%) ⬇️
pypy 93.37% <3.84%> (-0.19%) ⬇️
windows 93.34% <3.84%> (-0.19%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
astroid/brain/brain_gi.py 19.88% <3.84%> (-2.49%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Pierre-Sassoulas

Copy link
Copy Markdown
Member

Thank you for working on astroid. I didn't check the changes in detail, but the performance impact is worrying. Generally a brain is "dumb" using hard coded and very simple code is fine. Can't we do that for lower cost here ?

@Pierre-Sassoulas Pierre-Sassoulas added Enhancement ✨ Improvement to a component Brain 🧠 Needs a brain tip topic-performance labels May 16, 2026
@oreiche

oreiche commented May 17, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for taking the time to have a brief look at this. I share your concern; that's why I reported the numbers. However, we probably can't speed this up much further.

Please keep in mind that the numbers I've reported (additional ~3 seconds) were measured for an end-to-end run with pylint. The additional time spent is only partly caused by the brain's signature extraction, but also by the extended checks that pylint is able to do now.

Maybe some more data for you to have the full picture:

For Gtk (example.py), the time spent for generating all signatures goes up from 0.013 to 1.355 seconds. The remaining extra ~1.6 seconds are not spent in the brain. Furthermore, almost all of the additional time in the brain is caused by the inspect.signature() call, which is run for all 49807 functions and 48942 methods in Gtk. The sheer amount of calls is part of the issue, we probably can't avoid.

For GLib, a significantly smaller library (1713 functions and 2505 methods), the time spent in the brain for generating all signatures "only" goes up from 0.001 to 0.087 seconds.

Anyway, this PR is merely a suggestion from an idea I had since my fix for the pyobject method classification. Feel free to close it if you think this enhancement is not worth the additional cost. 😄

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the oreiche/gi-exact-signatures branch from b8940a6 to c8472a4 Compare May 24, 2026 12:05
@Pierre-Sassoulas Pierre-Sassoulas changed the base branch from main to codspeed-wizard-1774989768270 May 24, 2026 12:05
@codspeed-hq

codspeed-hq Bot commented May 24, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 3 untouched benchmarks


Comparing oreiche:oreiche/gi-exact-signatures (a616556) with main (c50a1f4)

Open in CodSpeed

@Pierre-Sassoulas Pierre-Sassoulas force-pushed the codspeed-wizard-1774989768270 branch 2 times, most recently from 2d391a6 to 2ef6d50 Compare May 24, 2026 13:23
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the oreiche/gi-exact-signatures branch from c8472a4 to b3773cb Compare May 24, 2026 14:35
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the codspeed-wizard-1774989768270 branch 2 times, most recently from 2fb0a52 to 7e482f9 Compare June 6, 2026 05:51
@Pierre-Sassoulas Pierre-Sassoulas deleted the branch pylint-dev:main June 6, 2026 21:41
@Pierre-Sassoulas Pierre-Sassoulas changed the base branch from codspeed-wizard-1774989768270 to main June 6, 2026 21:44
@Pierre-Sassoulas Pierre-Sassoulas force-pushed the oreiche/gi-exact-signatures branch from b3773cb to a616556 Compare June 6, 2026 21:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Brain 🧠 Needs a brain tip Enhancement ✨ Improvement to a component topic-performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants