Skip to content

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

Merged
merged 1 commit into from
Jul 30, 2018
Merged

Implement Record.get() #331

merged 1 commit into from
Jul 30, 2018

Conversation

elprans
Copy link
Member

@elprans elprans commented Jul 28, 2018

Record.get() allows record objects to better masquerade as dicts.

Fixes: #330.

@elprans elprans requested a review from 1st1 July 28, 2018 13:38
@elprans elprans force-pushed the record-get branch 2 times, most recently from 7fb9732 to 6e008b3 Compare July 28, 2018 13:43
record_item_by_name(ApgRecordObject *o, PyObject *item)
{
PyObject *mapped = PyObject_GetItem(o->desc->mapping, item);
if (mapped != NULL) {
Copy link
Member

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; }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or goto noitem;

if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &defval))
return NULL;

val = record_item_by_name(o, key);
Copy link
Member

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@elprans elprans force-pushed the record-get branch 2 times, most recently from 49f2164 to d3d5421 Compare July 28, 2018 16:28

noitem:
_PyErr_SetKeyError(item);
return -2;
Copy link
Member

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.

Copy link
Member Author

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.
@elprans elprans merged commit 2b93ee5 into master Jul 30, 2018
@elprans elprans deleted the record-get branch July 30, 2018 18:15
No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants