python-attrs / python-attrs/attrs

TypeError when calling super() in decorated method

Open
#1,038 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
Dominant language
Python
Stars
5.8k
Forks
480
Avg merge
2h 15m
Merged PRs (30d)
2

Description

Following code:

import attrs


def decorated(method):
    def wrapped(self, *args, **kwargs):
        return method(self, *args, **kwargs)

    return wrapped


@attrs.define()
class A:
    def f(self):
        pass


@attrs.define()
class B(A):
    @decorated
    def f(self):
        super().f()


B().f()

raises following error

TypeError: super(type, obj): obj must be an instance or subtype of type

If I use super(B, self), everything works just fine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the supplied Python reproduction first and confirm the TypeError occurs only with the decorated method and zero-argument super(). Then trace attrs.define() handling of decorated methods and add a regression test for B().f(); done means the example works without changing super() to super(B, self).

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.