@@ -530,6 +530,7 @@ typedef struct {
530530 PyObject *concrete_types;
531531 PyObject *get_type_hints;
532532 PyObject *get_class_annotations;
533+ PyObject *call_annotate_forwardref;
533534 PyObject *get_typeddict_info;
534535 PyObject *get_dataclass_info;
535536 PyObject *convert_generic_alias;
@@ -6120,16 +6121,12 @@ structmeta_collect_fields(StructMetaInfo *info, MsgspecState *mod, bool kwonly)
61206121 Py_DECREF(annotate);
61216122 return 0;
61226123 }
6123- PyObject *format = PyLong_FromLong(1); /* annotationlib.Format.VALUE */
6124- if (format == NULL) {
6125- Py_DECREF(annotate);
6126- return -1;
6127- }
6128- annotations = PyObject_CallOneArg(
6129- annotate, format
6130- );
6124+ /* Use Format.FORWARDREF so unresolved names do not raise NameError
6125+ * while the class body is still executing. See PEP 649 / annotationlib:
6126+ * https://docs.python.org/3/library/annotationlib.html#using-annotations-in-a-metaclass
6127+ */
6128+ annotations = PyObject_CallOneArg(mod->call_annotate_forwardref, annotate);
61316129 Py_DECREF(annotate);
6132- Py_DECREF(format);
61336130 if (annotations == NULL) {
61346131 return -1;
61356132 }
@@ -9910,7 +9907,7 @@ encoder_encode_into_common(
99109907}
99119908
99129909PyDoc_STRVAR(Encoder_encode__doc__,
9913- "encode(self, obj)\n"
9910+ "encode(self, obj, / )\n"
99149911"--\n"
99159912"\n"
99169913"Serialize an object to bytes.\n"
@@ -13804,7 +13801,7 @@ static PyTypeObject Encoder_Type = {
1380413801};
1380513802
1380613803PyDoc_STRVAR(msgspec_msgpack_encode__doc__,
13807- "msgpack_encode(obj, *, enc_hook=None, order=None)\n"
13804+ "msgpack_encode(obj, /, *, enc_hook=None, order=None)\n"
1380813805"--\n"
1380913806"\n"
1381013807"Serialize an object as MessagePack.\n"
@@ -14891,7 +14888,7 @@ JSONEncoder_encode(Encoder *self, PyObject *const *args, Py_ssize_t nargs)
1489114888}
1489214889
1489314890PyDoc_STRVAR(JSONEncoder_encode_lines__doc__,
14894- "encode_lines(self, items)\n"
14891+ "encode_lines(self, items, / )\n"
1489514892"--\n"
1489614893"\n"
1489714894"Encode an iterable of items as newline-delimited JSON, one item per line.\n"
@@ -14997,7 +14994,7 @@ static PyTypeObject JSONEncoder_Type = {
1499714994};
1499814995
1499914996PyDoc_STRVAR(msgspec_json_encode__doc__,
15000- "json_encode(obj, *, enc_hook=None, order=None)\n"
14997+ "json_encode(obj, /, *, enc_hook=None, order=None)\n"
1500114998"--\n"
1500214999"\n"
1500315000"Serialize an object as JSON.\n"
@@ -16762,7 +16759,7 @@ mpack_decode(
1676216759}
1676316760
1676416761PyDoc_STRVAR(Decoder_decode__doc__,
16765- "decode(self, buf)\n"
16762+ "decode(self, buf, / )\n"
1676616763"--\n"
1676716764"\n"
1676816765"Deserialize an object from MessagePack.\n"
@@ -16845,7 +16842,7 @@ static PyTypeObject Decoder_Type = {
1684516842
1684616843
1684716844PyDoc_STRVAR(msgspec_msgpack_decode__doc__,
16848- "msgpack_decode(buf, *, type='Any', strict=True, dec_hook=None, ext_hook=None)\n"
16845+ "msgpack_decode(buf, /, *, type='Any', strict=True, dec_hook=None, ext_hook=None)\n"
1684916846"--\n"
1685016847"\n"
1685116848"Deserialize an object from MessagePack.\n"
@@ -19734,7 +19731,7 @@ msgspec_json_format(PyObject *self, PyObject *args, PyObject *kwargs)
1973419731
1973519732
1973619733PyDoc_STRVAR(JSONDecoder_decode__doc__,
19737- "decode(self, buf)\n"
19734+ "decode(self, buf, / )\n"
1973819735"--\n"
1973919736"\n"
1974019737"Deserialize an object from JSON.\n"
@@ -19791,7 +19788,7 @@ JSONDecoder_decode(JSONDecoder *self, PyObject *const *args, Py_ssize_t nargs)
1979119788}
1979219789
1979319790PyDoc_STRVAR(JSONDecoder_decode_lines__doc__,
19794- "decode_lines(self, buf)\n"
19791+ "decode_lines(self, buf, / )\n"
1979519792"--\n"
1979619793"\n"
1979719794"Decode a list of items from newline-delimited JSON.\n"
@@ -19922,7 +19919,7 @@ static PyTypeObject JSONDecoder_Type = {
1992219919};
1992319920
1992419921PyDoc_STRVAR(msgspec_json_decode__doc__,
19925- "json_decode(buf, *, type='Any', strict=True, dec_hook=None)\n"
19922+ "json_decode(buf, /, *, type='Any', strict=True, dec_hook=None)\n"
1992619923"--\n"
1992719924"\n"
1992819925"Deserialize an object from JSON.\n"
@@ -20937,7 +20934,14 @@ convert_int(
2093720934 return ms_decode_int_enum_or_literal_pyint(obj, type, path);
2093820935 }
2093920936 else if (type->types & MS_TYPE_FLOAT) {
20940- return ms_decode_float(PyLong_AsDouble(obj), type, path);
20937+ double val = PyLong_AsDouble(obj);
20938+ if (val == -1.0 && PyErr_Occurred()) {
20939+ /* `obj` is out of range for a C double (PyLong_AsDouble sets
20940+ * OverflowError but still returns -1.0); without this check
20941+ * that error leaks past this function as a SystemError. */
20942+ return ms_error_with_path("Number out of range%U", path);
20943+ }
20944+ return ms_decode_float(val, type, path);
2094120945 }
2094220946 else if (
2094320947 type->types & MS_TYPE_DECIMAL
@@ -22705,6 +22709,7 @@ msgspec_clear(PyObject *m)
2270522709 Py_CLEAR(st->concrete_types);
2270622710 Py_CLEAR(st->get_type_hints);
2270722711 Py_CLEAR(st->get_class_annotations);
22712+ Py_CLEAR(st->call_annotate_forwardref);
2270822713 Py_CLEAR(st->get_typeddict_info);
2270922714 Py_CLEAR(st->get_dataclass_info);
2271022715 Py_CLEAR(st->rebuild);
@@ -22779,6 +22784,7 @@ msgspec_traverse(PyObject *m, visitproc visit, void *arg)
2277922784 Py_VISIT(st->concrete_types);
2278022785 Py_VISIT(st->get_type_hints);
2278122786 Py_VISIT(st->get_class_annotations);
22787+ Py_VISIT(st->call_annotate_forwardref);
2278222788 Py_VISIT(st->get_typeddict_info);
2278322789 Py_VISIT(st->get_dataclass_info);
2278422790 Py_VISIT(st->rebuild);
@@ -22981,6 +22987,7 @@ PyInit__core(void)
2298122987 SET_REF(concrete_types, "_CONCRETE_TYPES");
2298222988 SET_REF(get_type_hints, "get_type_hints");
2298322989 SET_REF(get_class_annotations, "get_class_annotations");
22990+ SET_REF(call_annotate_forwardref, "call_annotate_forwardref");
2298422991 SET_REF(get_typeddict_info, "get_typeddict_info");
2298522992 SET_REF(get_dataclass_info, "get_dataclass_info");
2298622993 SET_REF(typing_annotated_alias, "_AnnotatedAlias");
0 commit comments