Skip to content

slots=True do not play nice with __init_subclass__ #269

Closed

Description

@malinoff

A class annotated with attr.s(slots=True) can't call super().__init__subclass__ within its own __init_subclass__ method - a TypeError: super(type, obj): obj must be an instance or subtype of type is raised.

Reproducible example (tested on 16.3.0, 17.2.0 and f7f53d4) is here: https://repl.it/Mmkb/0

Activity

  1. added this to the 17.3 milestone on Oct 17, 2017
  2. hynek commented on Oct 17, 2017

    @hynek
    Member

    Uh is that another thing with cells? Is it fixable? And more importantly, is this something we’re breaking with #260 for dict classes too? :|

  3. Tinche commented on Oct 17, 2017

    @Tinche
    Member

    I'll take a look. This is a PEP 487 thing I see, Python 3.6+.

  4. Tinche commented on Oct 17, 2017

    @Tinche
    Member

    It's fixable. I can push a commit to the replace-class branch a little later.

  5. Tinche commented on Oct 17, 2017

    @Tinche
    Member

    So I'm sitting here trying to write a test for this and for some reason, the test I've written is passing even when I comment out the fix.

    Turns out CPython will actually reuse closure cells sometimes. So if a class has a normal method that needs to be rewritten, the problem will not manifest. 😱

  6. hynek commented on Oct 20, 2017

    @hynek
    Member

    JFTR @malinoff, you prevented us from making a huge mistake and release it – in the last minute! So many thanks for that!

  7. malinoff commented on Oct 20, 2017

    @malinoff
    Author

    @hynek my pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions