You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Out of the box mypy will properly catch errors when using
msgspec.json.encode / msgspec.msgpack.encode
msgspec.json.decode / msgspec.msgpack.decode
msgspec.json.Decoder / msgspec.msgpack.Decoder
msgspec.json.Encoder / msgspec.msgpack.Encoder
This includes inferring the output type of the decode methods. It will also properly infer the type and presence/absence of attributes on msgspec.Struct objects. But it won't properly catch errors in the struct constructors.
importmsgspecclassPoint(msgspec.Struct):
x: inty: intp=Point(1, 2)
p.x+"string"# mypy will catch this, since it knows `Point.x` is an intp=Point("oops", "bad") # this won't be caught by mypy
IIUC we'd need a mypy plugin to support this, similar to what pydantic does.
Activity
ian-r-rose commentedon Feb 12, 2022
I think this is what PEP 681 is intended to address. It isn't accepted, but an experimental version is available in pyright today.
jcrist commentedon Feb 24, 2022
Yeah, we're already using that for pyright support (see https://github.com/jcrist/msgspec/blob/e25177e7ecb5f6593dbc38ddfdccdbc13e13daa8/msgspec/__init__.pyi#L4-L28). We'll still likely want a mypy plugin, since it doesn't look like mypy will support this any time soon.
Fix `Meta(pattern=..)` memory leak / corruption (msgspec#1256)