GithubHelp home page GithubHelp logo

Doc suggestions about msgspec HOT 1 CLOSED

jcrist avatar jcrist commented on May 14, 2024
Doc suggestions

from msgspec.

Comments (1)

jcrist avatar jcrist commented on May 14, 2024

Thanks @ian-r-rose!!! These are excellent notes - I'm going to leave this open until I clarify the docs on these points.

Answering a few of your questions inline:

I am not sure what the current state of the art is for the places where a type is used in a value position, as is the case for your Decoder class. Probably it's not backwards compatible enough for you.

Yeah, those won't work on older versions of python. PEP 585 & PEP 604 only work with older versions of python when written as annotations (anything after the :), providing that from __future__ import annotations is applied (which makes the annotations strings, which runtime tooling then needs to interpret). This is because mypy/pyright/whatever are interpreting the annotations themselves, rather than relying on the standard python objects doing so. Since we need the types at runtime, we'd have to be able to interpret the newer syntax manually, since the stdlib won't. Other libraries that make use of annotations for runtime effects (e.g. pydantic) also have the same restrictions.

Does msgspec support implicit Optiona

No, but it won't error nicely (yet) either if the default value is invalid for the specified type. Mypy & pyright will catch that error statically though, so that's a partial solution.

Does the "Avoid Decoding Unused Fields" trick work with asarray=True?

Yes.

Can enc_hook also be given to add custom handling to a type the msgspec does natively support? Like, if I wanted to use it to truncate a float or something, could I do it?

No, not currently. If a type is natively supported, how it's handled can't be modified. Only custom types can be customized.

It's not a problem with the docs, but I also found myself wondering if it was in scope to have any translation code to things like openapi/jsonschema.

I think some utilities for generating jsonschema/openapi specs from type definitions would be in scope. Since we don't support all the type annotations provided by jsonschema though (and probably won't, I don't see all jsonschema features as in scope), automatically generating type definitions from a schema wouldn't be in scope.

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.