Coder Social home page Coder Social logo

Comments (2)

jcrist avatar jcrist commented on June 19, 2024 1

Yeah, this is a restriction of how dataclass_transform works (PEP 681). Since we want to support both mypy and pyright, I'm unwilling to fix this by writing a custom mypy extension - we want to follow the upstream python standards alone. You have two options:

  • pass frozen=True to the definition of Child as well (this is what I recommend)
  • Add type: ignore on the same line as class Child. This will ignore that error in mypy, but won't catch issues where you try to mutate Child.

We run into the same option-isn't-inherited issue with kw_only (which we made non-inherited to match what mypy/pyright expect). In that case I'm considering adding a new base class like KWStruct that defines the default to be kw_only=True, which would work better with dataclass_transform for cases where you want all subclasses to be keyword-only.

We could do the same here and define a FrozenStruct base class that defaults to frozen=True. If we do this, we might also want to change frozen to be non-inherited to match the dataclass_transform implementation.

from msgspec.

wikiped avatar wikiped commented on June 19, 2024

Thanks for quick feedback.

I have had considered two options you mentioned, but both look like an "inconvience" and therefore was hoping to find "a better way" to address this.

The FrozenStruct idea (and KWStruct) sounds like both developer and linter friendly way to solve this.

from msgspec.

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.