8000 gh-119180: PEP 649: Add __annotate__ attributes by JelleZijlstra · Pull Request #119209 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-119180: PEP 649: Add __annotate__ attributes #119209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
better error
  • Loading branch information
JelleZijlstra committed May 21, 2024
commit e2e2bde63299bd1bfe68a7f17165baa8f185db10
2 changes: 1 addition & 1 deletion Lib/test/test_type_annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ def check_annotations(self, f):
print(f.__annotations__)

f.__annotate__ = lambda x: 42
with self.assertRaisesRegex(TypeError, r"__annotate__ returned a non-dict"):
with self.assertRaisesRegex(TypeError, r"__annotate__ returned non-dict of type 'int'"):
print(f.__annotations__)

f.__annotate__ = lambda x: {"x": x}
Expand Down
4 changes: 2 additions & 2 deletions Objects/funcobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,8 +529,8 @@ func_get_annotation_dict(PyFunctionObject *op)
return op->func_annotations;
}
if (!PyDict_Check(ann_dict)) {
PyErr_SetString(PyExc_TypeError,
"__annotate__ returned a non-dict");
PyErr_Format(PyExc_TypeError, "__annotate__ returned non-dict of type '%.100s'",
Py_TYPE(ann_dict)->tp_name);
Py_DECREF(ann_dict);
return NULL;
}
Expand Down
3 changes: 2 additions & 1 deletion Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,8 @@ module_get_annotations(PyModuleObject *m, void *Py_UNUSED(ignored))
return NULL;
}
if (!PyDict_Check(annotations)) {
PyErr_SetString(PyExc_TypeError, "__annotate__ returned a non-dict");
PyErr_Format(PyExc_TypeError, "__annotate__ returned non-dict of type '%.100s'",
Py_TYPE(annotations)->tp_name);
Py_DECREF(annotate);
Py_DECREF(annotations);
Py_DECREF(dict);
Expand Down
3 changes: 2 additions & 1 deletion Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,8 @@ type_get_annotations(PyTypeObject *type, void *context)
return NULL;
}
if (!PyDict_Check(annotations)) {
PyErr_SetString(PyExc_TypeError, "__annotate__ returned a non-dict");
PyErr_Format(PyExc_TypeError, "__annotate__ returned non-dict of type '%.100s'",
Py_TYPE(annotations)->tp_name);
Py_DECREF(annotations);
Py_DECREF(annotate);
return NULL;
Expand Down
0