Giter VIP home page Giter VIP logo

pygobject-stubs's Introduction

Typing Stubs for PyGObject

PyPI

Installation

$ pip install pygobject-stubs

Configuration

Some libraries exist in multiple versions like Gtk3/4. As both libraries are currently imported under the namespace Gtk only stubs for one can be installed.

You need to decide this at install time either by using the --config-settings option with pip

$ pip install pygobject-stubs --no-cache-dir --config-settings=config=Gtk3,Gdk3,Soup2

or by setting the PYGOBJECT_STUB_CONFIG env variable

$ PYGOBJECT_STUB_CONFIG=Gtk3,Gdk3,Soup2 pip install --no-cache-dir pygobject-stubs

If no configuration is set, the most recent version of each library is installed.

--no-cache-dir is only necessary on subsequent reinstalls, otherwise the stubs will not be rebuild and a cache of a previous installation is used.

Project Integration

Usually you want the stubs to be installed as part of the development dependencies. pyproject.toml does not allow to pass config-settings to requirements. If you need specific versions of some libraries you can use a requirements.txt file instead, which allows to pass config-settings per requirement as of pip >= 23.1.0.

$ pip install . -r dev.txt

Contributing

Guide

pygobject-stubs's People

Contributors

aboghazala avatar artscoop avatar bedsteler20 avatar buzz avatar cal0pteryx avatar charlieqle avatar eggplants avatar jtojnar avatar lazka avatar lovetox avatar matperc avatar mrinmoyhaloi avatar mrvladus avatar mswiger avatar principis avatar razzeee avatar shibotto avatar souzomain avatar thecapypara avatar tingping avatar ydirson avatar yelodevopsi avatar zephvr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pygobject-stubs's Issues

PyCharm IDE: Stubs for binary module (GTK) won't generate from remote interpreter

What steps will reproduce the problem?

Have remote Debian based machine with active display (tested on https://coral.ai/products/dev-board/)
Set up remote interpreter via SSH in PyCharm (2021.1) / Windows 10 to that machine
On remote machine install PyGObject (as described here https://pygobject.readthedocs.io/en/latest/getting_started.html#ubuntu-getting-started)
In PyCharm create & run basic application:

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

window = Gtk.Window(title="Hello World")
window.show()
window.connect("destroy", Gtk.main_quit)
Gtk.main()

What is the expected result?

Application will run successfully
Stubs will be created an autocomplete will be available in PyCharm
What happens instead?

Application runs successfully
Stubs are not created with error:
Cannot find reference Gtk in '__init__.py'

Please provide any additional information below.
Attach a code sample as text, a screenshot or screencast if possible

I am setting up environment for developing on Coral DevBoard (and using TPU subprocessor) and need to use Gtk, GStreamer libraries with GTK3.
Unfortunately, stubs are not generated which makes it so much harder to use these libraries. I have tried all solutions mentioned in the existing issues but they mostly focus on local development, not remote interpreter.

Installed packages:
Package Version


certifi 2020.12.5
chardet 4.0.0
cloudpickle 1.6.0
cycler 0.10.0
decorator 4.4.2
distro-info 0.21
edgetpuvision 7.0
filterpy 1.1.0
gobject 0.1.0
httplib2 0.19.0
idna 2.10
imageio 2.9.0
kiwisolver 1.3.1
lap 0.4.0
Mako 1.0.7
Markdown 3.0.1
MarkupSafe 1.1.0
matplotlib 3.3.4
netifaces 0.10.9
networkx 2.5
numpy 1.20.1
Pillow 8.1.2
pip 21.0.1
protobuf 3.15.6
pycairo 1.16.2
pycoral 1.0.1
pycurl 7.43.0.2
PyGObject 3.40.1
PyGObject-stubs 0.0.2
PyJWT 2.0.1
PyOpenGL 3.1.5
pyparsing 2.4.7
pyserial 3.5
PySimpleSOAP 1.16.2
python-apt 1.8.4.3
python-dateutil 2.8.1
python-debian 0.1.39
python-debianbts 3.1.0
python-periphery 2.3.0
PyWavelets 1.1.1
reportbug 7.5.3-deb10u1
requests 2.25.1
scikit-image 0.18.1
scipy 1.1.0
setuptools 40.8.0
six 1.12.0
svgwrite 1.4.1
tflite-runtime 2.5.0
tifffile 2021.3.17
unattended-upgrades 0.1
urllib3 1.24.1
vitalsd 1.0
wheel 0.32.3

Please see also https://youtrack.jetbrains.com/issue/PY-48160 and https://youtrack.jetbrains.com/issue/PY-39158

Is --no-cache-dir required in order to update from Gtk4 to Gtk3 or vice versa

If I accidentally install the package without any --config-settings then I get stubs for the the latest Gtk4 version. If I wanna fix my mistake and install stubs for Gtk3 just using
pip install --force-reinstall --config-settings=config=Gtk3,Gdk3,Soup2 pygobject-stubs
gives the same Gtk4 stubs.

The only way to fix that for me was using --no-cache-dir:
pip install --force-reinstall --config-settings=config=Gtk3,Gdk3,Soup2 pygobject-stubs

I was wondering if I missed anything here, or it is required to switch the version of stubs.

Black formatted files fail to parse

Currently parser fails while parsing overrides in the _Gtk3.pyi

tools/generate.py Gtk 3.0 -o ./src/gi-stubs/repository/_Gtk3.pyi

fails with

Traceback (most recent call last):
  File "/home/lovetox/projects/pygobject-stubs/tools/generate.py", line 947, in <module>
    overrides = parse.parse(file.read())
                ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lovetox/projects/pygobject-stubs/tools/parse.py", line 170, in parse
    overridden_symbols = _search_overridden_symbols(input)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lovetox/projects/pygobject-stubs/tools/parse.py", line 69, in _search_overridden_symbols
    raise ParseError(f"Wrong indentation at line: {i}")

Seems it does not expect function definitions on module level having multiple lines

@mat-xc

Generate code automatically via tools provided by JetBrains?

git clone --depth 1 https://github.com/JetBrains/intellij-community.git /tmp/idea
mkdir /tmp/out
for typelib in Atk GLib GModule GObject Gdk GdkPixbuf Gio Gtk Pango; do
    python3 /tmp/idea/python/helpers/generator3.py -d /tmp/out -x gi.repository.$typelib $(python3 -c "from gi.repository import $typelib; print($typelib.__path__[-1])")
done

And stubs can be found under /tmp/out. Currently this repository seems to be much incomplete?

some problems in pygobject installation

Collecting pygobject
  Using cached https://files.pythonhosted.org/packages/8c/1f/76533985b054473ef6ab1ba4d9c00d62da502f8b43d3171ae588ec81ae93/PyGObject-3.30.4.tar.gz
Requirement already satisfied: pycairo>=1.11.1 in ./Application/anaconda3/lib/python3.6/site-packages (from pygobject) (1.18.1)
Building wheels for collected packages: pygobject
  Running setup.py bdist_wheel for pygobject: started
  Running setup.py bdist_wheel for pygobject: finished with status 'error'
  Complete output from command /home/zengchang/Application/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-3xwlsq4p/pygobject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" bdist_wheel -d /tmp/pip-wheel-4ei2f011 --python-tag cp36:
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/__init__.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/pygtkcompat.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  copying pygtkcompat/generictreemodel.py -> build/lib.linux-x86_64-3.6/pygtkcompat
  creating build/lib.linux-x86_64-3.6/gi
  copying gi/__init__.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_propertyhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_option.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_gtktemplate.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/importer.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/module.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/pygtkcompat.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_compat.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_ossighelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_error.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_signalhelper.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/types.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/docstring.py -> build/lib.linux-x86_64-3.6/gi
  copying gi/_constants.py -> build/lib.linux-x86_64-3.6/gi
  creating build/lib.linux-x86_64-3.6/gi/repository
  copying gi/repository/__init__.py -> build/lib.linux-x86_64-3.6/gi/repository
  creating build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GObject.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/keysyms.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GdkPixbuf.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gdk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gio.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/GLib.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Pango.py -> build/lib.linux-x86_64-3.6/gi/overrides
  copying gi/overrides/Gtk.py -> build/lib.linux-x86_64-3.6/gi/overrides
  running build_ext
  pycairo: new API
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1241, in <module>
      main()
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1236, in main
      zip_safe=False,
    File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/setuptools/__init__.py", line 143, in setup
      return distutils.core.setup(**attrs)
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 188, in run
      self.run_command('build')
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1076, in run
      self._setup_extensions()
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1071, in _setup_extensions
      add_pycairo(gi_cairo_ext)
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1055, in add_pycairo
      ext.include_dirs += [get_pycairo_include_dir()]
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 877, in get_pycairo_include_dir
      include_dir = find_path(find_new_api())
    File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 822, in find_new_api
      import cairo
    File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/cairo/__init__.py", line 1, in <module>
      from ._cairo import *  # noqa: F401,F403
  ImportError: /home/zengchang/Application/anaconda3/lib/python3.6/site-packages/cairo/_cairo.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cairo_svg_surface_set_document_unit
  
  ----------------------------------------
  Failed building wheel for pygobject
  Running setup.py clean for pygobject
Failed to build pygobject
Installing collected packages: pygobject
  Running setup.py install for pygobject: started
    Running setup.py install for pygobject: finished with status 'error'
    Complete output from command /home/zengchang/Application/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-3xwlsq4p/pygobject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-rmd60thi/install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    creating build
    creating build/lib.linux-x86_64-3.6
    creating build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/__init__.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/pygtkcompat.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    copying pygtkcompat/generictreemodel.py -> build/lib.linux-x86_64-3.6/pygtkcompat
    creating build/lib.linux-x86_64-3.6/gi
    copying gi/__init__.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_propertyhelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_option.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_gtktemplate.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/importer.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/module.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/pygtkcompat.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_compat.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_ossighelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_error.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_signalhelper.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/types.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/docstring.py -> build/lib.linux-x86_64-3.6/gi
    copying gi/_constants.py -> build/lib.linux-x86_64-3.6/gi
    creating build/lib.linux-x86_64-3.6/gi/repository
    copying gi/repository/__init__.py -> build/lib.linux-x86_64-3.6/gi/repository
    creating build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/__init__.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GIMarshallingTests.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GObject.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/keysyms.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GdkPixbuf.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gdk.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gio.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/GLib.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Pango.py -> build/lib.linux-x86_64-3.6/gi/overrides
    copying gi/overrides/Gtk.py -> build/lib.linux-x86_64-3.6/gi/overrides
    running build_ext
    pycairo: new API
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1241, in <module>
        main()
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1236, in main
        zip_safe=False,
      File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/setuptools/__init__.py", line 143, in setup
        return distutils.core.setup(**attrs)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/core.py", line 148, in setup
        dist.run_commands()
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/setuptools/command/install.py", line 61, in run
        return orig.install.run(self)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/command/install.py", line 545, in run
        self.run_command('build')
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/command/build.py", line 135, in run
        self.run_command(cmd_name)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "/home/zengchang/Application/anaconda3/lib/python3.6/distutils/dist.py", line 974, in run_command
        cmd_obj.run()
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1076, in run
        self._setup_extensions()
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1071, in _setup_extensions
        add_pycairo(gi_cairo_ext)
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 1055, in add_pycairo
        ext.include_dirs += [get_pycairo_include_dir()]
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 877, in get_pycairo_include_dir
        include_dir = find_path(find_new_api())
      File "/tmp/pip-install-3xwlsq4p/pygobject/setup.py", line 822, in find_new_api
        import cairo
      File "/home/zengchang/Application/anaconda3/lib/python3.6/site-packages/cairo/__init__.py", line 1, in <module>
        from ._cairo import *  # noqa: F401,F403
    ImportError: /home/zengchang/Application/anaconda3/lib/python3.6/site-packages/cairo/_cairo.cpython-36m-x86_64-linux-gnu.so: undefined symbol: cairo_svg_surface_set_document_unit
    
    ----------------------------------------
Command "/home/zengchang/Application/anaconda3/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-3xwlsq4p/pygobject/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-rmd60thi/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-3xwlsq4p/pygobject/

When I use pip install pygobject install the package, I got the error information above. How can I solve it? Do you have any idea?

Add a license for the project

There should be a license for the project. Most of the open source projects have them. The PyGobject project uses LGPL v2.1. And two other projects in the pygobject organization uses it. So I guess this repository should also use that.

Possible way to type hint callbacks

Right now we hint all the callables that admits variable arguments as Callable[..., T]. Starting from python 3.10 we can use the combination of Concatenate and ParamSpec. Link to documentation.

So for example GAsyncReadyCallback can be typed as

__P__ = ParamSpec("__P__")

Callable[Concatenate[GObject.Object, Gio.AsyncResult, __P__], None]

@lovetox there are any plans to support 3.10?

Doesn't seem to work with Gtk4

Looks like the stubs are for Gtk3 and no way to detect the version imported via pygobject? I guess this is a fundamental limitation of the apparoach?

Encode version info in the import

require_version doesn't work, we need to switch stubs based on the import name

e.g. from gi.repository import Gtk_3_0 as Gtk

There also is if typing.TYPE_CHECKING: so we can play with this without having to change pygobject

generate.py script output is different, and lacking, compared to stubs included in the repo

I'm trying to manually create the stubs for Gtk 4, but I've noticed that the generate.py script included in the repo lacks a ton of critical information compared to the stubs included in the repo.

When comparing locally generated stubs with the repo, I see that:

  • imports are missing
  • many types on root level functions are missing
  • base class information is missing

Basically locally generated stubs are useless for type checking.

Is the script out of date? How can I recreate those *.pyi files on my machine, so that they include all the information present in this repo?

how do you install it?

Do I have to do anything apart from :
pip install PyGObject-stubs

I wonder, as I'm trying to use it to get rid of pyright error reports. Pip install fixes complaining about Gtk symbol, but now I get:
No named parameter:title
on this line:
window = Gtk.Window(title="hello world!")

Possible to publish the different API versions as extras, instead?

I was just wondering, as I came here to once again look up the correct install incantation to properly install the correct versions of the type stubs into a given project:

Is there any way anyone can think of, that the differently-versioned stubs for a given module could be published as package extras, instead of build configuration options?

Beyond making pygobject-stubs easier to install...

# No longer this...
PYGOBJECT_STUB_CONFIG=Gtk3,Gdk3,Soup2 \
pip install pygobject-stubs --no-cache-dir

# Or this...
pip install pygobject-stubs --no-cache-dir \
--config-settings=config=Gtk3,Gdk3,Soup2

# But instead, this...
pip install 'pygobject-stubs[Gtk3,Gdk3,Soup2]'

The real win would be that projects using the various GObject modules could include them directly in their development dependencies list, with the versions already preselected to match the project code. (No more grepping a project's code for require_version just to determine all of the module versions that need to be defined for the pygobject-stubs install.)

Right now, there's no point in listing pygobject-stubs in a project's dependencies, because it'll be installed incorrectly without the configuration envvar/argument.

I'm not even sure it's possible (I certainly don't have any ideas how to make it work), but I'm not 100% sure it's IM-possible either. So I figured I'd throw it out there for brainstorming.

Import "gi.repository.GLib" could not be resolved from source

After I did: pip install pygobject-stubs --no-cache-dir --config-settings=config=Gtk4,Gdk4,Soup3 (for gtk4), or just the default install(pip install pygobject-stubs pygobject), my vim still reports above warning, it runs, but the warning stays no matter what.

Type of user_data is None throughout the stubs

user_data is obviously meant for the programmer to put arbitrary data in for later use. At runtime it may be any type. However, user_data is typed as None throughout these stubs.

Here is an example:

import gi

gi.require_version('Gtk', '3.0')

from gi.repository import Gtk

it = Gtk.TreeIter()
it.user_data = 0

This is what mypy says:

$ mypy repr.py
repr.py:8: error: Incompatible types in assignment (expression has type "int", variable has type "None")  [assignment]
Found 1 error in 1 file (checked 1 source file)

Here is the definition of TreeIter in _Gtk3.pyi:

class TreeIter(GObject.GBoxed):
    stamp: int = ...
    user_data: None = ...
    user_data2: None = ...
    user_data3: None = ...
    def copy(self) -> TreeIter: ...
    def free(self) -> None: ...

Merge with other gi-stub package

Hi,

we developed our own gi-stub package here https://dev.gajim.org/gajim/gi-stubs

Because we want to offer it to everybody, and hope people contribute to it, we would like to ask if there is interest to merge it into this official project.

Main benefits are:

  • All functions available
  • Classes have all the methods
  • Some methods are already typed though only the most common
  • All the contstants and GEnums / GFlags are completely typed
  • More gi libs (Soup, Gst, GSound, ... )

Whats missing:

  • Base classes need to be added to the classes
  • method args are not typed
  • Think about using more elaborate concepts like Generic Types etc

ImportError: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined symbol: ffi_type_uint32, version LIBFFI_BASE_7.0

Hi hope you all doing good.

i have install PyGObject but when I run .py module I got this error.

not found any solution.

python ds_app.py 
Traceback (most recent call last):
  File "ds_app.py", line 23, in <module>
    from deepstream.utils.common import is_aarch64
  File "/home/experts-vision/Documents/Jetson-app/Jetson_client/deepstream/../deepstream/utils/common.py", line 7, in <module>
    import gi
  File "/home/experts-vision/anaconda3/envs/deep/lib/python3.8/site-packages/gi/__init__.py", line 42, in <module>
    from . import _gi
ImportError: /lib/x86_64-linux-gnu/libgobject-2.0.so.0: undefined symbol: ffi_type_uint32, version LIBFFI_BASE_7.0

The Gdk[3].RGBA constructor's arguments are out of order

In the _Gdk3 stubs for Gdk.RGBA, it claims the constructor's signature is: __init__(self, blue, green, red, alpha). Pretty sure it's not! (It's kind of right there in the name, "R-G-B-A".)

class RGBA(GObject.GBoxed):
red: float = ...
green: float = ...
blue: float = ...
alpha: float = ...
# override
def __init__(
self,
blue: float = 1.0,
green: float = 1.0,
red: float = 1.0,
alpha: float = 1.0,
): ...

It almost looks like the colors were just blindly alphabetized, or something. (Though that wouldn't explain how alpha stayed at the end.)

GInterface Classes should probably not inherit from GObject

I think it was an error to do this.

Seems Gio.Networkmonitor is some kind of exception.

The more common case is something like Soup3.AuthManager which implements SessionFutures.

SessionFutures defines in its doc, that any class who implements this interface needs to inherit from GObject.

The problem now is that we let SessionFutures inherit from GObject, but also AuthManager, which leads to an error that python cant determine the inheritence correctly.

So in the case of AuthManager, it would be better if the interface does not inherit from GObject, because all Objects who implement it inherit already from GObject.

@mat-xc

GLib.timeout_add_seconds has different arguments than stub.

My code uses GLib.timeout_add_seconds with interval and function as the arguments, but MyPy is complaining:

error: Unexpected keyword argument "interval" for "timeout_add_seconds"  [call-arg]
error: Unexpected keyword argument "function" for "timeout_add_seconds"  [call-arg]

The stubs indicate that the arguments should be seconds and func:

def timeout_add_seconds(seconds: int, func: Callable[..., Any], *args: Any) -> int: ...

But when I use those arguments, I get:

TypeError: timeout_add_seconds() missing 2 required positional arguments: 'interval' and 'function'

I'm using require_version for Gtk 3 and AppIndicator.

import gi

gi.require_version("Gtk", "3.0")
gi.require_version("AppIndicator3", "0.1")

Should I be specifying a GLib version too?

For now, I'll just pass values as positional arguments, but I would much rather use kwargs.

Property are not typed correctly

Some properties should be typed as Optional but aren't. For example Gtk.Application active_window can be NULL.

Probably all the Object properties should be marked as Optional.

Data looks incorrect, causing mypy to create false alarms

Take this valid peace of python code:

#!/usr/bin/python3

from gi.repository import GObject

foo = GObject.ParamFlags.READWRITE

print(foo)

With pygobject-stubs installed, mypy throws this error:

error: "Type[ParamFlags]" has no attribute "READWRITE"  [attr-defined]
    foo = GObject.ParamFlags.READWRITE

Which is expected when having a look at the code: The GObject.pyi file does have a ParamFlags attribute, but that does not have a READWRITE attribute. Instead READWRITE is an attribute to GObject. The same issue is true for each and everything in all the .pyi files. Is this by intention? Is it expected to be incompatible to mypy?

Automated publish to pypi via Actions

We could add a Github action to publish automatically on release

there is a public Action for that available, all you need to add is a secret API token from pipy

@lazka i can setup the action but it seems i dont have access to the token settings, could you look into it if you have time?

Support GLib.option (or use a better placeholder)

Here is a simple example:

from gi.repository import GLib

parser = GLib.option.OptionParser(option_list=[
    GLib.option.make_option('--flag', action='store_true', help='flag'),
])
parser.parse_args()
print('flag is', parser.values.flag)

mypy complains about type errors:

$ mypy repr.py
repr.py:3: error: "ellipsis" has no attribute "OptionParser"  [attr-defined]
repr.py:4: error: "ellipsis" has no attribute "make_option"  [attr-defined]
Found 2 errors in 1 file (checked 1 source file)

It looks like the placeholder for this attribute is currently a literal ellipsis:

option = ... # FIXME Constant

I believe stubgen annotates attributes with _typeshed.Incomplete when the type cannot be determined. typing.Any would probably work as well.

Gtk 4 and libadwaita support

Its been a long time since gtk4 released. December 16, 2020. almost 3 months. And also libadwaita is stable now. Shouldn't there be stubs for both of these now ?

Methods of `Gtk.WidgetClass` that also exist on `Gtk.Widget` can not be used as class methods.

Trying to call a Gtk.WidgetClass class method on something like Gtk.TextView raises a type error, because the generated typestubs make something like Gtk.WidgetClass.add_shortcut a method of Gtk.TextView, which is semi-correct. It's both a method on Gtk.Widget but also a class method of Gtk.WidgetClass which type[Gtk.TextView] should implement.

I haven't 100% checked if this a general incompatibility with Gtk.WidgetClass.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.