imprv: always use __init__ instead of __new__#295
Merged
bryanforbes merged 1 commit intopygobject:masterfrom Apr 18, 2026
Merged
imprv: always use __init__ instead of __new__#295bryanforbes merged 1 commit intopygobject:masterfrom
__init__ instead of __new__#295bryanforbes merged 1 commit intopygobject:masterfrom
Conversation
For structs and boxed objects, PyGObject uses `__new__` for the constructor named "new" under certain cases along with a dummy `__init__` that does nothing. In addition, some `GObject.Object` overrides use `__new__` (ex. `Pango.Layout`) and some struct and boxed overrides use both `__new__` and `__init__` or one or the other. Finally, PyGObject incorrectly uses `Self` in their type annotations. The following changes have been made to handle all of these scenarios: - `__new__` and `__init__` handling has been moved to ClassInfo.__build_init() - For structs and boxed, `__new__` is used to build `__init__` when either `__new__` is the same as the "new" method from `__info__` or `__new__` exists directly on the class; otherwise, `__init__` is used - For `GObject.Object` subclasses, `__new__` is used when it exists directly on the class; otherwise, `__init__` is built from the writable, construct, and construct-only props - Writing all constructors as `__init__` eliminates the improper use of `Self` that comes from PyGObject
4b1c94b to
2cff169
Compare
Collaborator
Author
|
@xclaesse this fixes the errors about |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For structs and boxed objects, PyGObject uses
__new__for the constructor named "new" under certain cases along with a dummy__init__that does nothing. In addition, someGObject.Objectoverrides use__new__(ex.Pango.Layout) and some struct and boxed overrides use both__new__and__init__or one or the other. Finally, PyGObject incorrectly usesSelfin their type annotations. The following changes have been made to handle all of these scenarios:__new__and__init__handling has been moved to ClassInfo.__build_init()__new__is used to build__init__when either__new__is the same as the "new" method from__info__or__new__exists directly on the class; otherwise,__init__is usedGObject.Objectsubclasses,__new__is used when it exists directly on the class; otherwise,__init__is built from the writable, construct, and construct-only props__init__eliminates the improper use ofSelfthat comes from PyGObject