Question about calling function from parent class

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
User avatar
Roy_043
Veteran
Posts: 8547
Joined: Thu Dec 27, 2018 12:28 pm

Question about calling function from parent class

Post by Roy_043 »

In the Draft code I sometimes encounter functions similar to:

Code: Select all

    def onDocumentRestored(self, obj):
        """Execute code when the document is restored.

        It calls the parent class to add missing annotation properties.
        """
        super().onDocumentRestored(obj)
I do not fully understand why they are there. They override the function from the parent class, and then only call that function. The code obviously also works without them. Are they perhaps just there to inform the programmer? Some coding standard?
User avatar
onekk
Veteran
Posts: 6205
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Question about calling function from parent class

Post by onekk »

I don't know exactly, but speaking about annotations, I remember a discussion with Yorick about a way to make "annotations styles" works.

As they are saved inside some custom fields to not modify the FCStd format, there were a mechanism that check if a document contains these "style data" and reapply them once the document is opened.

As I see a call of the super() class probably the main class of FC, so it reminds me that mechanism.

@yorik

Hope it helps.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
Post Reply