Giter VIP home page Giter VIP logo

Comments (2)

biqqles avatar biqqles commented on August 22, 2024

DataClassMeta.new is invoked once by the dataclass decorator, and then once again going up the chain from Derived -> Base -> DataClassMeta (-> type), which sees the result of the first invocation and decides it doesn't need to add any new slots, only to have the result of the first invocation lost in the final result. Does that sound like a reasonable version of events?

Yes, if I understand your explanation correctly, this is indeed what happens. Using a metaclass means that DataClassMeta.__new__ is run for each new subclass, then applying the decorator means the subclass is replaced with a new version (this happens here if you are interested). It can cause issues.

If you're wondering, the way my fix works is by exploiting the fact that the dict_ passed in looks different between these two invocations. In the first instance (subclassing), the metaclass is called before Python has done any of its inheritance magic, meaning __slots__ is empty. In the second instance (decorator usage), the class is already fully formed, meaning __slots__ has been set, so it's not replaced.

This change also means that a user-defined __slots__ will not be wiped out which I think is good anyway.

from dataclassy.

thisisrandy avatar thisisrandy commented on August 22, 2024

Thanks for the detailed explanation and quick fix. I'm not sure I had it 100% in my original explanation, but it's clear what was going on now.

from dataclassy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.