Skip to content

MAINT: Ensure that parsing errors are passed on even in tests. - #11173

Merged
mattip merged 1 commit into
numpy:masterfrom
mhvk:gufunc-avoid-wasting-time-writing-parser
May 30, 2018
Merged

mattip merged 1 commit into
numpy:masterfrom
mhvk:gufunc-avoid-wasting-time-writing-parser

Conversation

@mhvk

@mhvk mhvk commented May 27, 2018

Copy link
Copy Markdown
Contributor

To avoid it wasting a few hours of someone else's time if they edit the gufunc signature parser....

cc @mattip, since he may just have suffered similar problems...

Comment thread numpy/core/src/umath/_umath_tests.c.src Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Multiline comments like so:

/*
 * blah
 * blah
 */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@mhvk
mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from cdac054 to a72fb26 Compare May 28, 2018 00:59

@mattip mattip left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@eric-wieser

Copy link
Copy Markdown
Member

Can you change addUfuncs to return an error code too?

Comment thread numpy/core/src/umath/_umath_tests.c.src Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not sure this comment is necessary - any PyObject * allocation can fail due to memory limits, so we should always check results like this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, I'll maybe leave this as a breadcrump for the future - or to remind myself of hours waster...

Comment thread numpy/core/src/umath/_umath_tests.c.src Outdated

@eric-wieser eric-wieser May 29, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In multiarraymodule.c we use

#if defined(NPY_PY3K)
#define RETVAL(x) x
PyMODINIT_FUNC PyInit_multiarray(void) {
#else
#define RETVAL(x)
PyMODINIT_FUNC initmultiarray(void) {
#endif

would be nice to have a consistent macro here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Wasn't aware of that - like it much better, so will change.

@eric-wieser eric-wieser left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A clear improvement, but I think we could be a little more consistent with how we do things elsewhere here

@mhvk
mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch 2 times, most recently from 6aaed56 to 4a47c42 Compare May 29, 2018 13:09
Comment thread numpy/core/src/umath/_umath_tests.c.src Outdated

@eric-wieser eric-wieser May 29, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Either:

  • Testing PyErr_Occurred() is pointless
  • There is a bug in PyUFunc_FromFuncAndDataAndSignature which fails to set an exception correctly

I'm assuming the former, meaning you can just call PyErr_Print() unconditionally

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Maybe I was being overly defensive here, but the docs for PyErr_Print are very specific that one should be sure an error is set otherwise bad things happen. Normally, of course, we'd just return NULL here and let downstream take care of it, but here we're setting a new error and I thought it was useful to at least print the old one.

But if you think this really doesn't make sense, I'll take it out (I had it out when I first added the return value).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suppose my point is that addUfuncs() < 0 is already our test to be sure that an error is set. If we returned -1 but forgot to set an error, that's a bug.

Also it seems that PyErr_Print is perfectly ok with there being no error anyway. So I'd say keep the PyErr_Print(), but drop the condition guarding it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So much for trusting the documentation... OK, condition dropped.

Comment thread numpy/core/src/umath/_umath_tests.c.src Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In principle we should be checking the return value of PyDict_SetItemString too, but I'm happy for you to declare that out of scope for this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, let's do that - I think if we're just calling standard python interface routines, we can be a bit more cavalier; we mostly need to guard against our own mistakes!

@mhvk
mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from 4a47c42 to e88c23e Compare May 29, 2018 19:02
To avoid it wasting a few hours of someone else's time if they
edit the gufunc signature parser.
@mhvk
mhvk force-pushed the gufunc-avoid-wasting-time-writing-parser branch from e88c23e to 0091127 Compare May 29, 2018 21:00
@mattip
mattip merged commit 896393b into numpy:master May 30, 2018
@mattip

mattip commented May 30, 2018

Copy link
Copy Markdown
Member

Thanks Marten

@mhvk
mhvk deleted the gufunc-avoid-wasting-time-writing-parser branch May 30, 2018 19:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants