Skip to content

Conversation

@xclaesse
Copy link
Contributor

No description provided.

@xclaesse
Copy link
Contributor Author

I started adding some typing for the easy parts: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/10238.

This PR is an update of stubs with that GStreamer PR applied.

pre-commit fails all overrides with PYI020 [*] Quoted annotations should not be included in stubs. I think it requires Python 3.13: https://docs.python.org/3/library/inspect.html#inspect.Signature.format.

@xclaesse xclaesse force-pushed the gst-typing branch 3 times, most recently from 031e1c2 to 14a4c21 Compare December 2, 2025 13:29
@lovetox
Copy link
Collaborator

lovetox commented Dec 2, 2025

Why are class attributes now after the init?

@xclaesse
Copy link
Contributor Author

xclaesse commented Dec 2, 2025

@lovetox That's a side effect of c04550f.

_find_methods() returns every attributes, not only methods, including GI fields. classret = _gi_build_stub() was then skipping GI fields because they were handled separately after printing the constructor. I changed to handle GI fields directly inside classret = _gi_build_stub() because that's where we can ensure that an attribute name cannot be used multiple times, e.g. as method and constant. That means GI fields are now together with other class constants.

That solve an issue with at least GstIterator that has both gst_iterator_next() function and GstIterator.next callable attribute. I think fundamentally that API cannot be translated to python because of the name conflict, pygobject gives precedence to the method which is the most useful.

@lovetox
Copy link
Collaborator

lovetox commented Dec 2, 2025

Do you think you can put them again in front?

@xclaesse
Copy link
Contributor Author

xclaesse commented Dec 3, 2025

@lovetox ok, managed to preserve ordering.

@lovetox
Copy link
Collaborator

lovetox commented Dec 3, 2025

Thanks looks better now.

Why are we importing Self typing extensions, i dont see it used anywhere

If typing extensions is indeed necessary, then we would need to add it as dependency in pyproject.toml

EDIT: Found where Self is used

@xclaesse
Copy link
Contributor Author

xclaesse commented Dec 3, 2025

If typing extensions is indeed necessary, then we would need to add it as dependency in pyproject.toml

done.

More generally, overrides could import any extra modules, maybe at some point we'll need a more generic way.

@xclaesse xclaesse force-pushed the gst-typing branch 3 times, most recently from aee4398 to bae9adb Compare December 5, 2025 15:08
@lovetox
Copy link
Collaborator

lovetox commented Dec 5, 2025

Could you rebase your commits on current master, the enum fix is already in master.

I want to test your generator changes against the other libs and if it does not introduce unwanted changes, we can merge.

@xclaesse
Copy link
Contributor Author

xclaesse commented Dec 5, 2025

@lovetox done

@lovetox
Copy link
Collaborator

lovetox commented Dec 5, 2025

I tested and found no regression with Gtk and GLib, which are probably the most used stubs.

Can you please prefix commits with the prefixes described in CONTRIBUTING.md, otherwise they will not properly included in the automatic generated changelog.

This requires python 3.14 to run the generator. When using older
Python, simply remove quotes and double-quotes.
This removes all local overrides because GStreamer upstream now has
typed override APIs.
When overrides defines for example:
```
class FooError(Exception):
  pass
```
_get_gname() was returning None for both FooError and Exception classes,
which means it was not excluding methods from Exception base class.
This fix typing of overrides that provide more pythonic syntax for
iterators, context manager, etc.
Overrides could define new classes, such as:
    class FooError(Exception):
        pass
@xclaesse
Copy link
Contributor Author

xclaesse commented Dec 5, 2025

@lovetox done

@lovetox lovetox merged commit 0f9c3c1 into pygobject:master Dec 6, 2025
2 checks passed
@lovetox
Copy link
Collaborator

lovetox commented Dec 6, 2025

Thanks for the improvments to the generator !

@xclaesse xclaesse deleted the gst-typing branch December 6, 2025 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants