Question

I have the following code:

template_response = super(ExtendedUserAdmin, self).render_change_form(*args, **kwargs)

How should I wrap it so it doesn't exceed 78 characters? Currently, the limit occurs right before *args.

I am using Python 2.7.

Was it helpful?

Solution 2

I do:

template_response = super(ExtendedUserAdmin, self).render_change_form(
    *args, **kwargs)

or

template_response = super(
    ExtendedUserAdmin, self
).render_change_form(*args, **kwargs)

or

template_response = super(
    ExtendedUserAdmin, self).render_change_form(*args, **kwargs)

OTHER TIPS

You can store the result of super() in a local name:

sproxy = super(ExtendedUserAdmin, self)
template_response = sproxy.render_change_form(*args, **kwargs)

I would wrap after the opening parenthesis:

class X:
    def render_change_form(self, *args, **kwargs):
        template_response = super(ExtendedUserAdmin, self).render_change_form(
            *args, **kwargs)

Luckily this is just short enough to fall within the limits. In general, I break after opening parentheses whenever possible. If the method name was a little longer, I would introduce a local name for super(ExtendedUserAdmin, self) as @MartijnPieters did.

I often do:

template_response = super(ExtendedUserAdmin, self
                          ).render_change_form(*args, **kwargs)

As at first look what is in super parenthesis doesn't interest me, that way it's more like in python3

template_response = super().render_change_form(*args, **kwargs)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top