Comments (1)
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)
- Inherit __init_subclass__ args to subclass HOT 1
- ormsgpack benchmark comparison HOT 1
- encode sort_keys argument HOT 16
- Allow more than one str-like type in unions HOT 5
- decode's strict=False does not cast floats to ints HOT 3
- Typed encoding HOT 1
- Validation on serialization HOT 5
- Make msgspec more aware of large data and other serialization protocols
- Recommendation for Efficiently Decoding BSON from PyMongo with msgspec
- leading underscores and `"camel"` rename strategy HOT 2
- Constraint check for typing.Optional field HOT 1
- Automatically support `functools.cached_property` without requiring setting `dict=True` HOT 2
- UnboundLocalError for `new_scope` HOT 3
- Sign release tags when making future releases? HOT 4
- How can I do data normalization on a frozen instance in `__post_init__`? HOT 1
- Cannot convert with `from_attributes` when using a rename convention HOT 3
- Cannot set `gc=False` on Generic structs? HOT 5
- Support types.MappingProxyType HOT 3
- Add either `init_omit_defaults` or `omit_none` HOT 5
- Consider making `DecodeError` and `ValidationError` inherit from `ValueError` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from msgspec.