Skip to content
  • Daniel Drake's avatar
    Fix property lookup in class hierarchy · 901c1b6e
    Daniel Drake authored
    Commit 4bfe7972 introduced a bug where
    a Python subclass of a gi-provided base class overrides a property from the
    base class.
    
    The new behaviour in the above commit causes pygobject to seek the property
    in the base class and try to read it from there (resulting in confusion)
    rather than noticing that the property is overridden and present in the
    Python object instance.
    
    To provide a nicer solution here, we can exploit the fact that
    g_object_class_find_property() will traverse the hierarchy in order to
    find the right GParamSpec, and the returned GParamSpec can tell us exactly
    which GType introduces the property. The strategy is:
    
     1. Find pspec with g_object_class_find_property()
     2. Find the class that owns that property (pspec->owner_type)
     3. See if girepository owns that class.
     3a. If yes, get property from there.
     3b. If not, get property "directly"
    
    And the same for property setting.
    
    Now that _pygi_lookup_property_from_g_type is always passed the type that
    implements the property, it no longer has to go recursing through parent
    classes, which was the original cause of confusion.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=686942
    901c1b6e