-
Notifications
You must be signed in to change notification settings - Fork 417
Implement Record.get() #331
New issue
Have a question about this project? No Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “No 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? No Sign in to your account
Conversation
7fb9732
to
6e008b3
Compare
asyncpg/protocol/record/recordobj.c
Outdated
record_item_by_name(ApgRecordObject *o, PyObject *item) | ||
{ | ||
PyObject *mapped = PyObject_GetItem(o->desc->mapping, item); | ||
if (mapped != NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (mapped == NULL) { return NULL; }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or goto noitem;
asyncpg/protocol/record/recordobj.c
Outdated
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &defval)) | ||
return NULL; | ||
|
||
val = record_item_by_name(o, key); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd actually make record_item_by_name
return -1 or 0 and not use PyErr_ExceptionMatches
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
49f2164
to
d3d5421
Compare
asyncpg/protocol/record/recordobj.c
Outdated
|
||
noitem: | ||
_PyErr_SetKeyError(item); | ||
return -2; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use an enum type, please. It's hard to read the code with checks for -1 or -2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
`Record.get()` allows record objects to better masquerade as dicts. Fixes: #330.
Record.get()
allows record objects to better masquerade as dicts.Fixes: #330.