| 1 |
======================== |
| 2 |
Initializer Deprecations |
| 3 |
======================== |
| 4 |
|
| 5 |
Starting with PyGObject 3.11, overridden object creation and initialization (``__new__`` and |
| 6 |
``__init__`` respectively) that contain side effects or dispatching beyond standard object creation |
| 7 |
with `g_object_newv <https://docs.gtk.org/gobject/ctor.Object.newv.html>`_ |
| 8 |
will issue deprecation warnings. Additionally, positional arguments and non-standard keyword |
| 9 |
argument names will also show deprecation warnings. |
| 10 |
|
| 11 |
Deprecations will be in the form of Gtk.PyGTKDeprecationWarning. These warnings are only issued in |
| 12 |
development releases (odd minor version, 3.9, 3.11, etc...). Stable releases with even minor |
| 13 |
versions will not show deprecations unless the "-Wd" command line option is specified when running |
| 14 |
Python. |
| 15 |
|
| 16 |
Updating calls which invoke these deprecations will work across all of the 3.x releases (backwards |
| 17 |
and forwards compatible) with the exception of Gtk.RecentChooserDialog(). With RecentChooserDialog, |
| 18 |
updating the "manager" argument to "recent_manager" (when used either positionally or as a keyword) |
| 19 |
is not compatible with versions of PyGObject prior to 3.11. However, the "manager" keyword is |
| 20 |
guaranteed to work across all versions of the 3.x series (even though a deprecation is printed). |
| 21 |
|
| 22 |
Rational |
| 23 |
======== |
| 24 |
|
| 25 |
1. Cut down class overrides for the benefit of performance. Having a large amount of class overrides |
| 26 |
causes each of the class types to be loaded and all of its GI methods added. |
| 27 |
|
| 28 |
2. Avoid the potential for silent creation bugs like `GnomeBug 711487 |
| 29 |
<http://bugzilla.gnome.org/show_bug.cgi?id=711487>`_ and inheritance confusion `GnomeBug 721226 |
| 30 |
<http://bugzilla.gnome.org/show_bug.cgi?id=721226>`_. |
| 31 |
|
| 32 |
3. Ensure consistency across all GObject creation. In essence, we would like to guarantee all |
| 33 |
objects can be created with the same technique: taking a variable number of keyword arguments |
| 34 |
mapped exactly to the classes property names as defined by using `g_object_newv |
| 35 |
<https://docs.gtk.org/gobject/ctor.Object.newv.html>`_. |
| 36 |
This will greatly help consistency, documentation, and discoverability/expectation once the |
| 37 |
API user understands property names are valid keyword arguments for object construction. |
| 38 |
|
| 39 |
4. Additional side effects when creating objects belong in explicitly named function (e.g. |
| 40 |
Gtk.IconSet.new_from_pixbuf) as opposed to overloading initializers to dispatch functionality. |
| 41 |
|
| 42 |
5. Dispatching/overloaded methods in general should be considered a sort of "anti-pattern". They |
| 43 |
add unnecessary support by requiring new methods of a similar class also be added to the |
| 44 |
dispatch. It also means we have to maintain custom documentation for the dispatching method. |
| 45 |
Additionally it can hurt readability when compared using explicitly named methods. Examples: |
| 46 |
|
| 47 |
.. code-block:: python |
| 48 |
|
| 49 |
cursor = Gdk.Cursor(display, cursor_type) |
| 50 |
cursor = Gdk.Cursor(display, pixbuf, x, y) |
| 51 |
|
| 52 |
The prior example at least uses variable names which give a clue to the reader. A worse example is |
| 53 |
shown with badly named variables: |
| 54 |
|
| 55 |
.. code-block:: python |
| 56 |
|
| 57 |
cursor = Gdk.Cursor(disp, c) |
| 58 |
cursor = Gdk.Cursor(disp, c, x, y) |
| 59 |
|
| 60 |
Explicit object creation enforces better readability as well as discoverability of documentation |
| 61 |
without having to dig into the dispatching method to figure out what is going on: |
| 62 |
|
| 63 |
.. code-block:: python |
| 64 |
|
| 65 |
cursor = Gdk.Cursor.new_for_display(display, cursor_type) |
| 66 |
cursor = Gdk.Cursor.new_from_pixbuf(display, pixbuf, x, y) |
| 67 |
|
| 68 |
References |
| 69 |
========== |
| 70 |
|
| 71 |
* Bugzilla ticket for this deprecation: `GnomeBug 705810 |
| 72 |
<http://bugzilla.gnome.org/show_bug.cgi?id=705810>`_ |
| 73 |
|
| 74 |
* `Mailing List Discussion |
| 75 |
<https://mail.gnome.org/archives/python-hackers-list/2013-August/msg00005.html>`_ |