• 
      

    Make it easy to get to an extension instance from a class.

    Review Request #5552 — Created Feb. 26, 2014 and submitted — Latest diff uploaded

    Information

    Djblets
    master
    27c457b...

    Reviewers

    It's pretty common for extension code to try to get the instance of the
    extension from places where the instance isn't passed. The common
    pattern is to import the extension class, the extension manager, and to
    do a fetch. While that works, it's annoying.

    Since an extension can only be instantiated once, it's pretty safe to
    store a handle to the instance on the class. Now,
    ExtensionSubclass.instance will point to the instance when the extension
    is enabled.

    Extensions may still need to deal with circular imports to get the class
    (depending on where it's calling this from), but that's not any
    different from before, and it's much nicer than dealing with the
    extension manager.

    Made use of this in an extension I'm building. I was able to fetch the
    instance from a form that didn't have the extension passed.