Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8344149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:16:28+00:00 2026-06-09T06:16:28+00:00

Are there good (suitable for using in real projects) ways or reducing boilerplate in

  • 0

Are there good (suitable for using in real projects) ways or reducing boilerplate in things like this

class B(A):
    def qqq(self): # 1 unwanted token "self"
        super(B, self).qqq() # 7 unwanted tokens plus 2 duplications ("B", "qqq")
        do_something()

I want it to look more like this:

class B(A):
    def qqq:
        super
        do_something()

or (more realistically)

class B(A):
    @autosuper_before
    def qqq(self):
        do_something()

Is it possible in Python 2.6+ without overt hacks?

@link super() in Python 2.x without args

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T06:16:31+00:00Added an answer on June 9, 2026 at 6:16 am

    tl;dr

    As the OP said “Is it possible in Python 2.6+ without overt hacks?”, the answer is: No

    Long version

    You can make a simple decorator that will call the next parent with this method. The problem is that you will not have control on the arguments you want to pass.

    Edit:
    This will not work for a subclass already using autosuper because it’ll chose the wrong class and make an infinite loop.

    def autosuper(fn):
        def f(self, *args, **kw):
            cl = super(type(self), self)
            getattr(cl, fn.__name__)(*args, **kw)
            return fn(self, *args, **kw)
        return f
    

    How could this be done? Python 3.x do have a super function that takes no arguments!

    Unfortunally, the Python 3.x’s super is a class and at the same time a keyword, because just the presence of its name will change the current environment to unveil a variable named __class__ that is the right class you need to use!

    If you check the frame inside a function declared in a class, there’s no __class__ variable and the co_freevars attribute of the frame’s f_code attribute is empty. When you write the name super (do not need to call it), the __class__ string will appear in co_freevars meaning it comes from another closure. Also, if you try to access the __class__ variable without using super, it’ll use the LOAD_DEFER bytecode for this same reason instead of LOAD_GLOBAL like would be normal to every undefined name.

    This is so crazy that you cannot just do hyper = super and call this new hyper variable without arguments (that is exactly the same object as super).

    As I cannot compete with this much of black magic inside the Python Interpreter, and because the autosuper decorator is not declared inside a class (so it can never access the __class__ variable even if that was possible in Python 2.x), I will not try to write a new decorator and will leave this answer here as a warn for other people who want to do that.

    It is probably possible to make some hackeries to find the right class to use, but I will not dig that far. Things to consider:

    • When the decorator is applied, the class do not exist yet, so this should be done when the decorated function is called.
    • The function being decorated is not yet an unbound method (that were removed anyway from Py3k) so you cannot check the im_class attribute.
    • The frame does not seem to hold any information of the class used to make this call (unless of course the __class__ variable do exist and it is possible to get a reference to it)
    • This answer provided by OP is also quite broken because it makes a lot of bad assumptions and has problems with decorated functions.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a good gem to track/log user activities on the site? Like when
Is there a good way to keep keys from conflicting when using the Microsoft
Good day! I know there has been lots of posts for this kind of
Are there some good resources tutorials or anyone has tried to implement a Capcha
Is there any good library which supports WebSockets and is compatible with GWT? Ideally,
Are there any good technical comparisons available between the various game development options available.
Is there a good C library for graph theoretic manipulations? I particularly need to
Is there a good C library that I can use in my client application
Is there a good way to start at a given index and move BACKWARDS
Are there any good technical solutions for extremely long term archiving of data, for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.